Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
850ccd5
use correct & operator.
apotonick Dec 22, 2015
402014e
use bootstrap instead of foundation
fran-worley Jan 20, 2016
0576478
Upgrade trailblazer & fix edit view
fran-worley Jan 20, 2016
902e212
Added basic form example for Bootstrap
fran-worley Jan 21, 2016
b247649
bigger form!
apotonick Jan 22, 2016
d285ba1
checkbox collections!
apotonick Jan 22, 2016
9baff07
added formula, enhanced forms
fran-worley Jan 22, 2016
90c0052
Merge branch 'master' of https://github.com/fran-worley/gemgem-sinatr…
apotonick Jan 22, 2016
2e13130
remove .form-group for several elements.
apotonick Jan 23, 2016
0e587fe
add benchmark puts to /posts/new.
apotonick Jan 23, 2016
d53e004
benchmark x50.
apotonick Jan 23, 2016
d7b86a5
add benchmark-ips.
apotonick Jan 23, 2016
ff68636
change ips settings.
apotonick Jan 23, 2016
82bdf05
remove benchmarking from controller.
apotonick Jan 23, 2016
4c23219
Merge branch 'formular-slim' into formular-slim-bootstrap3
apotonick Jan 28, 2016
100e2fa
add grid, thanks @fran-worley!
apotonick Jan 28, 2016
a1bf4b3
more grid magic.
apotonick Jan 28, 2016
ae75f83
select menu must have other name.
apotonick Jan 31, 2016
48f2a1a
newer formular API.
apotonick Feb 1, 2016
edb57ff
new API. style: :inline.
apotonick Feb 1, 2016
88facc6
Fix inline forms
fran-worley Feb 1, 2016
8cd13b5
Horizontal Forms Yey!!
fran-worley Feb 2, 2016
7e1e125
Add input groups
fran-worley Feb 9, 2016
ec2318f
new formula
fran-worley Jun 28, 2016
1139c3c
update to TRB cells.
apotonick Jun 28, 2016
b03b564
Let's enhance our form
fran-worley Jun 28, 2016
75de530
use new formular helper
fran-worley Jul 21, 2016
6519dcc
update for latest formular
fran-worley Sep 29, 2016
6ab26cb
use new select prompt option
fran-worley Dec 8, 2016
c3b4967
fix buttons
fran-worley Jun 11, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ source 'https://rubygems.org'
gem "sinatra"
gem "sinatra-sequel" # persistence
gem "sqlite3"
gem "trailblazer", "1.1.0.rc1" # operation
# gem "reform", "2.1.0.rc1" # validation
gem "reform", path: "../reform" # validation
gem "dry-validation", ">= 0.4.0"
gem "trailblazer", "1.1.0" # operation
#gem "dry-validation", "0.6.0"
gem "cells" # presentation
gem "cells-slim", ">= 0.0.4"
gem "trailblazer-cells"
gem "reform", "2.2.0" # validation
gem "dry-validation", "0.7.4" # validation

gem "rerun"
gem "benchmark-ips"

gem "trailblazer-cells", path: "../trailblazer-cells"

gem "rerun"

gem "formular", path: "../formular"
# gem "formular", git: "https://github.com/apotonick/formular.git"
91 changes: 78 additions & 13 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,49 +1,114 @@
PATH
remote: ../formular
specs:
formular (0.2.1)
declarative (~> 0.0.4)
uber (>= 0.0.11, < 0.2.0)

GEM
remote: https://rubygems.org/
specs:
bacon (1.2.0)
declarative (0.0.5)
benchmark-ips (2.6.1)
cells (4.1.1)
tilt (>= 1.4, < 3)
uber (>= 0.0.9)
cells-slim (0.0.5)
cells (>= 4.0.1, < 6.0.0)
slim (~> 3.0)
concurrent-ruby (1.0.2)
declarative (0.0.8)
uber (>= 0.0.15)
disposable (0.2.1)
declarative (~> 0.0.4)
disposable (0.3.1)
declarative (>= 0.0.8, < 1.0.0)
representable (>= 2.4.0, <= 3.1.0)
uber
dry-configurable (0.1.6)
concurrent-ruby (~> 1.0)
dry-container (0.3.4)
concurrent-ruby (~> 1.0)
dry-configurable (~> 0.1, >= 0.1.3)
dry-equalizer (0.2.0)
dry-logic (0.2.3)
dry-container (~> 0.2, >= 0.2.6)
dry-equalizer (~> 0.2)
dry-monads (0.0.1)
dry-types (0.7.2)
concurrent-ruby (~> 1.0)
dry-configurable (~> 0.1)
dry-container (~> 0.3)
dry-equalizer (~> 0.2)
dry-logic (~> 0.2, >= 0.2.3)
dry-monads (>= 0.0.1)
inflecto (~> 0.0.0, >= 0.0.2)
dry-validation (0.7.4)
concurrent-ruby (~> 1.0)
dry-configurable (~> 0.1, >= 0.1.3)
dry-container (~> 0.2, >= 0.2.8)
dry-equalizer (~> 0.2)
dry-logic (~> 0.2, >= 0.2.2)
dry-types (~> 0.6, >= 0.6.0)
ffi (1.9.10)
inflecto (0.0.2)
listen (3.1.5)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
ruby_dep (~> 1.2)
rack (1.6.4)
rack-protection (1.5.3)
rack
reform (2.1.0.rc1)
disposable (>= 0.2.1, < 0.3.0)
rb-fsevent (0.9.7)
rb-inotify (0.9.7)
ffi (>= 0.5.0)
reform (2.2.0)
disposable (>= 0.3.0, < 0.4.0)
representable (>= 2.4.0, < 3.1.0)
uber (~> 0.0.11)
representable (3.0.0)
declarative (~> 0.0.5)
uber (~> 0.0.15)
sequel (4.29.0)
sinatra (1.4.6)
rack (~> 1.4)
rerun (0.11.0)
listen (~> 3.0)
ruby_dep (1.3.1)
sequel (4.34.0)
sinatra (1.4.7)
rack (~> 1.5)
rack-protection (~> 1.4)
tilt (>= 1.3, < 3)
sinatra-sequel (0.9.0)
bacon
sequel (>= 3.2.0)
sinatra (>= 0.9.4)
slim (3.0.7)
temple (~> 0.7.6)
tilt (>= 1.3.3, < 2.1)
sqlite3 (1.3.11)
tilt (2.0.1)
trailblazer (1.1.0.rc1)
temple (0.7.7)
tilt (2.0.4)
trailblazer (1.1.0)
declarative
reform (>= 2.0.0, < 3.0.0)
uber (>= 0.0.15)
trailblazer-cells (0.0.2)
cells (>= 4.1.0.rc1, < 5.0.0)
uber (0.0.15)

PLATFORMS
ruby

DEPENDENCIES
reform (= 2.1.0.rc1)
benchmark-ips
cells
cells-slim (>= 0.0.4)
dry-validation (= 0.7.4)
formular!
reform (= 2.2.0)
rerun
sinatra
sinatra-sequel
sqlite3
trailblazer (= 1.1.0.rc1)
trailblazer (= 1.1.0)
trailblazer-cells

BUNDLED WITH
1.10.6
1.12.5
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ The following gems are used in this project.
| Dry-validation | Validation |
| Cells | Presentation |
| Slim | Presentation |
| Formular| Form Rendering |

## Run

Expand Down
1 change: 1 addition & 0 deletions app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

get "/posts/new" do
op = Post::Create.present({})

Post::Cell::New.(op, url: "/posts", layout: Gemgem::Cell::Layout).()
end

Expand Down
15 changes: 15 additions & 0 deletions benchmark.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require "benchmark/ips"
require "sinatra"
require_relative "config/init"


op = Post::Create.present({})

Benchmark.ips do |x|
# Configure the number of seconds used during
# the warmup phase (default 2) and calculation phase (default 5)
x.config(:time => 20, :warmup => 2)

# Typical mode, runs the block as many times as it can
x.report("cells") { Post::Cell::New.(op, url: "/posts", layout: Gemgem::Cell::Layout).() }
end
31 changes: 31 additions & 0 deletions concepts/post/cell/new.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,37 @@
require "formular"
#require 'formular/builders/bootstrap3'
module Post::Cell
class New < Trailblazer::Cell
include Formular::Helper

private
def vertical_form(model, url, **options, &block)
options[:builder] = :bootstrap3
form(model, url, options, &block)
#Formular::Builders::Bootstrap3.new(model: model, prefix_path: :comment).form(options, &block)
end

def inline_form(model, url, **options, &block)
options[:builder] = :bootstrap3_inline
form(model, url, options, &block)

#Formular::Builders::Bootstrap3Inline.new(model: model, prefix_path: :comment).form(options, &block)
end

def horizontal_form(model, url, **options, &block)
options[:builder] = :bootstrap3_horizontal
form(model, url, options, &block)
#Formular::Builders::Bootstrap3Horizontal.new(model: model, prefix_path: :comment).form(options, &block)
end

def options_array
[["Option 1", 1], ["Option 2", 2], ["Option 3", 3]]
end

def roles_array
[["Admin", 1], ["Owner", 2], ["Maintainer", 3]]
end

def url
options[:url] || raise("no action URL!")
end
Expand Down
22 changes: 16 additions & 6 deletions concepts/post/operation/create.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
require_relative "../../../models/post"
require 'reform/form/dry'

class Post::Create < Trailblazer::Operation
contract do
property :title
property :url_slug
property :content
property :is_public, virtual: true
property :owner
property :roles
property :select_roles, from: :roles

include Reform::Form::Dry::Validations

validation :default do
key(:title, &:filled?)
key(:url_slug) { |slug| slug.format?(/^[\w-]+$/) && slug.unique? }
key(:select_roles, &:filled?)
key(:url_slug) { |slug| slug.format?(/^[\w-]+$/) & slug.unique? }
key(:content) { |content| content.max_size?(10) } # i know that a real blog post should be a bit more elaborating.

def unique?(value)
form.model.class[url_slug: value].nil?
end
key(:roles) { |roles| roles.size?(2) }

configure { |config|
configure do
config.messages_file = 'concepts/post/operation/dry_error_messages.yml'
}

def unique?(value)
form.model.class[url_slug: value].nil?
end
end
end
end

Expand All @@ -27,6 +36,7 @@ def model!(*)
end

def process(params)
puts "@@@@@ #{params.inspect}"
validate(params) do
contract.save
end
Expand Down
75 changes: 61 additions & 14 deletions concepts/post/view/new.slim
Original file line number Diff line number Diff line change
@@ -1,14 +1,61 @@
h1 New Post!

form action="#{url}" method="post"
.row
input type="text" name="title" value=model.contract.title placeholder="Title"
.row
input type="text" name="url_slug" value=model.contract.url_slug disabled=model.contract.options_for(:url_slug)[:readonly] placeholder="URL slug"
.row
textarea name="content" placeholder="And your story..." rows="9"
=model.contract.content
.row
input type="submit" class="large button expand"

= model.contract.errors.messages.inspect
.row
.col-sm-6.col-sm-offset-3
.page-header.text-center
h1 New Post!

= vertical_form(model.contract, url) do |f|
.row
.col-sm-6
= f.input_group :title, label: "Title" do |input|
=input.group_addon('<input type="checkbox" value="1"/>')
=input.control
.col-sm-6
= f.input :url_slug, label: "URL Slug"

= f.input_group :url_slug, label: "URL", left_addon: 'http://', right_addon: '.com'

= f.select :select_roles, label: "Roles", collection: roles_array, prompt: 'Choose a role'

= f.inline_radio :select_roles, label: "Inline radios", collection: [[1, "Yes"], [2, "No"], [3, "I really don't know"]]

= f.inline_checkbox :select_roles, label: "Inline checkboxes", collection: options_array

hr
h4 Checkboxes in columns!
.row
.col-sm-4
= f.checkbox :select_roles, label: "Column 1", collection: options_array
.col-sm-4
= f.checkbox :select_roles, label: "Column 2", collection: options_array
.col-sm-4
= f.checkbox :select_roles, label: "Column 3", collection: options_array
hr

= f.textarea :content, placeholder: "And your story...", rows: 9
= f.checkbox :is_public, label: "Public?", value: "1"

= f.submit content: "Submit!", class: ['btn-lg']

.page-header.text-center
h1 Inline Form

= inline_form(model.contract, url) do |f|
= f.input :title
= f.input :url_slug, label: 'url slug', placeholder: "URL slug", label_options: { class: ["sr-only"] }
=f.submit(content: "Submit!")

.page-header.text-center
h1 Horizontal Form

= horizontal_form(model.contract, url) do |f|
= f.input_group :title, label: "Title" do |input|
=input.control
=input.group_btn("<a class='btn btn-default' href='#'>Suprise Me</a>")

= f.input :url_slug, label: 'URL'

= f.textarea :content, placeholder: "And your story...", rows: 9, label: 'Content'

= f.select :select_roles, collection: roles_array, label: 'Role', prompt: 'Choose a role'

= f.submit content: "Submit!", class: ['btn-lg']
9 changes: 5 additions & 4 deletions concepts/post/view/show.slim
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
a href="/posts/#{model.id}/edit"
| Edit
.page-header
h1
a href="/posts/#{model.id}/edit" class="btn btn-info" style="margin-right:10px;"
| Edit
= title

h1
= title

.content
= content
Expand Down
5 changes: 3 additions & 2 deletions config/migrations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
end
end

migration "add URL slug to posts" do
database.add_column :posts, :url_slug, String
migration "add owner and roles" do
database.add_column :posts, :owner, String
database.add_column :posts, :roles, String
end
4 changes: 0 additions & 4 deletions gemgem/cell/layout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ module Gemgem
module Cell
class Layout < Trailblazer::Cell
self.view_paths = ["."]

def content
@options[:content]
end
end
end
end
Loading