bff 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.ruby-version +1 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +6 -0
- data/app/views/bff/_form_builder.html.erb +122 -0
- data/bff.gemspec +33 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/bff.rb +8 -0
- data/lib/bff/builder.rb +35 -0
- data/lib/bff/engine.rb +6 -0
- data/lib/bff/version.rb +3 -0
- data/lib/bff/view_additions.rb +12 -0
- metadata +105 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 83fcf282800260b632b35b970a79d34cbd106f8a
|
4
|
+
data.tar.gz: 50a42ba09f11bdf5a3df243950519d11ac634fc2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1a37ee7eb14abc98229a5388555526a42a1d088505a86f5fc075337011aa57deacaef009640e32501ca349e86cdfd131f5a72cc5d93d153715fcdfabbc358b23
|
7
|
+
data.tar.gz: f78597d76af2719e917de338c73f6c520f35a9d5cd916b10b29f9add62fa005a0d949edd0d01b483824cea9a6da48bfd41aca47cf367f90fef3543b0539db06a
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.2.2
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Andrew Hunter
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Bff
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/bff`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'bff'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install bff
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/bff.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
<% builder.define :form, form_html: { } do |options| %>
|
2
|
+
<%= builder.form_tag record, options do |form| %>
|
3
|
+
<%= builder.render :errors if record.errors.present? %>
|
4
|
+
<%= yield builder %>
|
5
|
+
<% end %>
|
6
|
+
<% end %>
|
7
|
+
|
8
|
+
<% builder.define :errors, errors_html: { class: "alert alert-danger" } do |options| %>
|
9
|
+
<%= content_tag :div, options[:errors_html] do %>
|
10
|
+
<h5>Uh Oh! There were some errors in your entry.</h5>
|
11
|
+
<ul>
|
12
|
+
<%= builder.render :error,
|
13
|
+
collection: record.errors.full_messages,
|
14
|
+
wrap_each: { tag: "li" }%>
|
15
|
+
</ul>
|
16
|
+
<% end %>
|
17
|
+
<% end %>
|
18
|
+
|
19
|
+
<% builder.define :error do |error| %>
|
20
|
+
<%= error %>
|
21
|
+
<% end %>
|
22
|
+
|
23
|
+
<% builder.define lambda {|field| field.name },
|
24
|
+
collection: builder.fields,
|
25
|
+
as: :text_field do |form, field_name, options| %>
|
26
|
+
<%= builder.render options[:as], form, field_name, options %>
|
27
|
+
<% end %>
|
28
|
+
|
29
|
+
<%# ------------------- FIELD TYPES ----------------------------- %>
|
30
|
+
|
31
|
+
<% builder.define :text_field,
|
32
|
+
wrapper_html: { class: "form-group" },
|
33
|
+
input_html: { class: 'form-control' } do |form, field_name, options| %>
|
34
|
+
<%= content_tag :div, options[:wrapper_html] do %>
|
35
|
+
<%#= builder.render "#{field.name}_content" do %>
|
36
|
+
<%= builder.render :label, form, field_name, options %>
|
37
|
+
<%= form.text_field field_name, options[:input_html] %>
|
38
|
+
<%# end %>
|
39
|
+
<% end %>
|
40
|
+
<% end %>
|
41
|
+
|
42
|
+
<% builder.define :text_area,
|
43
|
+
wrapper_html: { class: "form-group" },
|
44
|
+
input_html: { rows: 5, class: 'form-control' } do |form, field_name, options| %>
|
45
|
+
<%= content_tag :div, options[:wrapper_html] do %>
|
46
|
+
<%#= builder.render "#{field.name}_content" do %>
|
47
|
+
<%= builder.render :label, form, field_name, options %>
|
48
|
+
<%= form.text_area :raw_data, options[:input_html] %>
|
49
|
+
<%# end %>
|
50
|
+
<% end %>
|
51
|
+
<% end %>
|
52
|
+
|
53
|
+
<% builder.define :hidden_field do |form, field_name, options| %>
|
54
|
+
<%= form.hidden_field field_name %>
|
55
|
+
<% end %>
|
56
|
+
|
57
|
+
<% builder.define :file_field,
|
58
|
+
browse_button_html: {
|
59
|
+
class: 'btn btn-info btn-medium',
|
60
|
+
onclick: lambda { |field_name| "$('input[id=#{field_name}]').click(); return false;" }
|
61
|
+
},
|
62
|
+
file_field_html: {
|
63
|
+
class: 'hidden',
|
64
|
+
id: lambda { |field_name| "#{field_name}"},
|
65
|
+
onchange: lambda { |field_name| "$('input[id=#{field_name}_text]').val($(this).val().replace('C:\\\\fakepath\\\\', ''));" }
|
66
|
+
},
|
67
|
+
wrapper_html: { class: "form-group" },
|
68
|
+
input_html: {
|
69
|
+
class: 'form-control',
|
70
|
+
id: lambda { |field_name| "#{field_name}_text"},
|
71
|
+
readonly: true,
|
72
|
+
onclick: lambda { |field_name| "$('input[id=#{field_name}]').click(); return false;" },
|
73
|
+
placeholder: "Click here or on 'Browse'"
|
74
|
+
},
|
75
|
+
browse_label: "Browse" do |form, field_name, options| %>
|
76
|
+
<%= content_tag :div, options[:wrapper_html] do %>
|
77
|
+
<%= builder.render :label, form, field_name, options %>
|
78
|
+
<div class="form-inline">
|
79
|
+
<%#= builder.render "#{field.name}_content" do %>
|
80
|
+
<%= form.file_field field_name, builder.call_each_hash_value_with_params(options[:file_field_html], field_name) %>
|
81
|
+
<%= form.text_field "#{field_name}_text", builder.call_each_hash_value_with_params(options[:input_html], field_name) %>
|
82
|
+
<%= link_to options[:browse_label], '#', builder.call_each_hash_value_with_params(options[:browse_button_html], field_name) %>
|
83
|
+
<%# end %>
|
84
|
+
</div>
|
85
|
+
<% end %>
|
86
|
+
<% end %>
|
87
|
+
|
88
|
+
<% builder.define :check_box,
|
89
|
+
wrapper_html: { class: "checkbox" },
|
90
|
+
input_html: {} do |form, field_name, options| %>
|
91
|
+
<%= content_tag :div, options[:wrapper_html] do %>
|
92
|
+
<%#= builder.render "#{field.name}_content" do %>
|
93
|
+
<%= form.label field_name, *builder.label_options(options) do %>
|
94
|
+
<%= form.check_box field_name, options[:input_html] %>
|
95
|
+
<%= options[:label] || field_name.to_s.titleize %>
|
96
|
+
<% end %>
|
97
|
+
<%# end %>
|
98
|
+
<% end %>
|
99
|
+
<% end %>
|
100
|
+
|
101
|
+
<% builder.define :label do |form, field_name, options| %>
|
102
|
+
<%= form.label field_name, *builder.label_options(options) %>
|
103
|
+
<% end %>
|
104
|
+
|
105
|
+
<% builder.define :submit,
|
106
|
+
label: "Next",
|
107
|
+
input_html: { class: 'btn btn-info btn-submit-top-margin' } do |form, field_name, options| %>
|
108
|
+
<br>
|
109
|
+
<div class="row">
|
110
|
+
<div class="col-xs-9">
|
111
|
+
By clicking the Next button, you agree to adhere to the
|
112
|
+
<%= link_to "Mobile Marketing Association Guidelines", "http://www.mmaglobal.com/files/bestpractices.pdf" %>
|
113
|
+
</div>
|
114
|
+
<div class="pull-right">
|
115
|
+
<%= form.submit options[:label], options[:input_html] %>
|
116
|
+
</div>
|
117
|
+
</div>
|
118
|
+
<% end %>
|
119
|
+
|
120
|
+
<%# ------------------- END OF FIELD TYPES ---------------------- %>
|
121
|
+
|
122
|
+
<%= builder.render :form %>
|
data/bff.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'bff/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "bff"
|
8
|
+
spec.version = Bff::VERSION
|
9
|
+
spec.authors = ["Andrew Hunter"]
|
10
|
+
spec.email = ["hunterae@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{BFF (meaning "Better Form For") - Easily build forms with customizable wrappers}
|
13
|
+
spec.description = %q{Form Builder with theme support and easy overrides how form fields and wrappers generate}
|
14
|
+
spec.homepage = "https://github.com/mobilecause/bff"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
31
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
32
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
33
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "bff"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/bff.rb
ADDED
data/lib/bff/builder.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
module Bff
|
2
|
+
class Builder < Blocks::Builder
|
3
|
+
attr_accessor :fields
|
4
|
+
attr_accessor :form
|
5
|
+
|
6
|
+
def initialize(*)
|
7
|
+
self.fields = []
|
8
|
+
super
|
9
|
+
end
|
10
|
+
|
11
|
+
def field(field_name, options={}, &block)
|
12
|
+
if definition_mode == Blocks::Builder::DEFINITION_MODE_TEMPLATE_OVERRIDES
|
13
|
+
fields << define(field_name, options, &block)
|
14
|
+
else
|
15
|
+
render(field_name, form, field_name, options, &block)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def form_tag(record, options={}, &block)
|
20
|
+
form_options = { html: options[:form_html] }
|
21
|
+
form_options[:url] = options[:url] if options[:url]
|
22
|
+
view.form_for record, form_options.deep_symbolize_keys do |form|
|
23
|
+
@form = form
|
24
|
+
view.capture(form, &block)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def label_options(options)
|
29
|
+
o = []
|
30
|
+
o << options[:label] if options[:label]
|
31
|
+
o << options[:label_html] if options[:label_html]
|
32
|
+
o
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/bff/engine.rb
ADDED
data/lib/bff/version.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'action_view'
|
2
|
+
|
3
|
+
module Bff
|
4
|
+
module ViewAdditions
|
5
|
+
def bff(record, options={}, &block)
|
6
|
+
BetterFormFor::Builder.new(self, options.merge(record: record)).render_template("bff/form_builder", &block)
|
7
|
+
end
|
8
|
+
alias better_form_for bff
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
ActionView::Base.send :include, Bff::ViewAdditions
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bff
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrew Hunter
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-07-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.12'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: Form Builder with theme support and easy overrides how form fields and
|
56
|
+
wrappers generate
|
57
|
+
email:
|
58
|
+
- hunterae@gmail.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".rspec"
|
65
|
+
- ".ruby-version"
|
66
|
+
- ".travis.yml"
|
67
|
+
- Gemfile
|
68
|
+
- LICENSE.txt
|
69
|
+
- README.md
|
70
|
+
- Rakefile
|
71
|
+
- app/views/bff/_form_builder.html.erb
|
72
|
+
- bff.gemspec
|
73
|
+
- bin/console
|
74
|
+
- bin/setup
|
75
|
+
- lib/bff.rb
|
76
|
+
- lib/bff/builder.rb
|
77
|
+
- lib/bff/engine.rb
|
78
|
+
- lib/bff/version.rb
|
79
|
+
- lib/bff/view_additions.rb
|
80
|
+
homepage: https://github.com/mobilecause/bff
|
81
|
+
licenses:
|
82
|
+
- MIT
|
83
|
+
metadata:
|
84
|
+
allowed_push_host: https://rubygems.org
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
requirements: []
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 2.4.5
|
102
|
+
signing_key:
|
103
|
+
specification_version: 4
|
104
|
+
summary: BFF (meaning "Better Form For") - Easily build forms with customizable wrappers
|
105
|
+
test_files: []
|