formie 1.0.3 → 1.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 +4 -4
- data/.github/workflows/rake.yml +28 -0
- data/.ruby-gemset +1 -1
- data/.ruby-version +1 -1
- data/.watchr +27 -16
- data/Appraisals +18 -8
- data/Gemfile +9 -7
- data/Gemfile.lock +155 -131
- data/MIT-LICENSE +3 -1
- data/README.md +48 -44
- data/Rakefile +5 -5
- data/formie.gemspec +19 -19
- data/gemfiles/{rails_5.1.gemfile → rails_6.1.gemfile} +6 -4
- data/gemfiles/{rails_5.0.gemfile → rails_7.0.gemfile} +6 -4
- data/lib/formie/version.rb +6 -8
- data/lib/formie.rb +9 -9
- data/test/controllers/orders_test.rb +6 -8
- data/test/integration/order_test.rb +13 -10
- data/test/internal/app/controllers/application_controller.rb +1 -2
- data/test/internal/app/controllers/orders_controller.rb +1 -3
- data/test/internal/app/models/order.rb +1 -3
- data/test/internal/app/views/orders/new.html.erb +1 -1
- data/test/internal/app/views/orders/show.html.erb +1 -1
- data/test/internal/config/routes.rb +1 -1
- data/test/internal/db/schema.rb +2 -4
- data/test/test_helper.rb +7 -7
- metadata +31 -65
- data/.rubocop.yml +0 -14
- data/.travis.yml +0 -36
- data/gemfiles/rails4_2.gemfile +0 -5
- data/gemfiles/rails_5.2.gemfile +0 -13
- data/gemfiles/rails_6.0.gemfile +0 -13
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
|
-
Formie
|
2
|
-
======
|
1
|
+
# Formie
|
3
2
|
|
4
3
|
[](https://badge.fury.io/rb/formie)
|
5
|
-
[](https://travis-ci.org/matique/formie)
|
6
4
|
|
7
5
|
Tired of programming each HTML tag?
|
8
6
|
Are you in search of DRYness for Rails views?
|
@@ -16,21 +14,14 @@ In short, Formie is like a helper using the notation of a partial.
|
|
16
14
|
|
17
15
|
Templates handlers are supported as in partials.
|
18
16
|
|
19
|
-
|
20
17
|
## Installation
|
21
18
|
|
22
19
|
As usual:
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
# Gemfile
|
29
|
-
gem 'formie'
|
30
|
-
|
31
|
-
$ bundle
|
32
|
-
|
33
|
-
Use 'gem install formie -v 0.7.1' for Rails 3.2.
|
20
|
+
```ruby
|
21
|
+
# Gemfile
|
22
|
+
gem "formie"
|
23
|
+
```
|
24
|
+
and run "bundle install".
|
34
25
|
|
35
26
|
## Description
|
36
27
|
|
@@ -43,6 +34,8 @@ Templates for Formie are hosted in:
|
|
43
34
|
Till Rails 5 <formie_path> is 'app/formies'.
|
44
35
|
Starting at Rails 6 <formie_path> is 'app/views/formies'.
|
45
36
|
|
37
|
+
Version 1.1.0+ is intended for Rails 7
|
38
|
+
|
46
39
|
Inside a formie the following locals (as delivered by the
|
47
40
|
controller) are available:
|
48
41
|
|
@@ -52,7 +45,7 @@ controller) are available:
|
|
52
45
|
| args | remainings after extracting options/locals
|
53
46
|
| block | block passed to the formie
|
54
47
|
| controller_name
|
55
|
-
| form | (available inside
|
48
|
+
| form | (available inside form_with (similar to fields_for))
|
56
49
|
| form.object
|
57
50
|
| params
|
58
51
|
|
@@ -61,45 +54,56 @@ The controller attributes are available as usual.
|
|
61
54
|
|
62
55
|
To avoid a server restart during development of formies you may add to:
|
63
56
|
|
64
|
-
|
57
|
+
```ruby
|
58
|
+
# app/controllers/application_controller.rb
|
65
59
|
|
66
|
-
|
67
|
-
|
68
|
-
|
60
|
+
before_filter do
|
61
|
+
Formie.reload if Rails.env.development?
|
62
|
+
end
|
63
|
+
```
|
69
64
|
|
70
65
|
|
71
|
-
## Examples
|
66
|
+
## Examples (see also tests)
|
72
67
|
|
73
|
-
|
74
|
-
|
75
|
-
|
68
|
+
```ruby
|
69
|
+
<%= copyright %>
|
70
|
+
<%= back %>
|
71
|
+
<%= show obj: @order %>
|
76
72
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
73
|
+
<%= form_with model: Order do |f| %>
|
74
|
+
<%= f.l_text_field :who %>
|
75
|
+
<%= f.l_text_field :amount %>
|
76
|
+
<% end %>
|
77
|
+
```
|
81
78
|
|
82
79
|
In directory <formie_path> :
|
83
80
|
|
84
|
-
|
85
|
-
|
81
|
+
```ruby
|
82
|
+
# application/copyright.html.erb
|
83
|
+
<div class="copyright"> Copyright (c) 2009 </div>
|
84
|
+
|
85
|
+
# application/back.html.erb
|
86
|
+
<a href="<%= "/#{h(controller_name)}" %>"> Back </a>
|
87
|
+
|
88
|
+
# application/show.html.erb
|
89
|
+
<a href="<%= "/#{h(controller_name)}/#{obj.id}" %>"> Show </a>
|
86
90
|
|
87
|
-
|
88
|
-
|
91
|
+
# forms/l_text_field.html.erb
|
92
|
+
<% field = args.first %>
|
93
|
+
<p>
|
94
|
+
<%= form.label field %><br />
|
95
|
+
<%= form.text_field field %>
|
96
|
+
</p>
|
89
97
|
|
90
|
-
|
91
|
-
|
98
|
+
# templates/hello.slim
|
99
|
+
/ a comment
|
92
100
|
|
93
|
-
|
94
|
-
|
95
|
-
<p>
|
96
|
-
<%= form.label field %><br />
|
97
|
-
<%= form.text_field field %>
|
98
|
-
</p>
|
101
|
+
span Hello Slim
|
102
|
+
```
|
99
103
|
|
100
|
-
|
101
|
-
/ a comment
|
104
|
+
## Miscellaneous
|
102
105
|
|
103
|
-
|
106
|
+
Copyright (c) 2009-2022 Dittmar Krall (www.matiq.com),
|
107
|
+
released under the MIT license:
|
104
108
|
|
105
|
-
|
109
|
+
* https://opensource.org/licenses/MIT
|
data/Rakefile
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
require
|
1
|
+
require "rake/testtask"
|
2
2
|
|
3
|
-
desc
|
3
|
+
desc "Run the tests."
|
4
4
|
Rake::TestTask.new do |t|
|
5
|
-
t.libs <<
|
6
|
-
t.libs <<
|
7
|
-
t.pattern =
|
5
|
+
t.libs << "lib"
|
6
|
+
t.libs << "test"
|
7
|
+
t.pattern = "test/**/*_test.rb"
|
8
8
|
t.verbose = false
|
9
9
|
end
|
10
10
|
|
data/formie.gemspec
CHANGED
@@ -1,33 +1,33 @@
|
|
1
|
-
lib = File.expand_path(
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
-
require
|
3
|
+
require "formie/version"
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
|
-
s.name
|
7
|
-
s.version
|
8
|
-
s.summary
|
6
|
+
s.name = "formie"
|
7
|
+
s.version = Formie::VERSION
|
8
|
+
s.summary = "Formie is like a Rails helper, but uses the notation of a partial."
|
9
9
|
s.description = <<-'END'
|
10
10
|
Formie implements low level template-based Rails helpers. It injects
|
11
11
|
the formies into the ActionView module. The form-bounded as well as
|
12
12
|
the unbounded templates are supported. Still, the ActionView
|
13
13
|
functionality (e.g. text_field) is kept untouched.
|
14
14
|
END
|
15
|
-
s.authors
|
16
|
-
s.email
|
17
|
-
s.homepage
|
15
|
+
s.authors = ["Dittmar Krall"]
|
16
|
+
s.email = ["dittmar.krall@matiq.com"]
|
17
|
+
s.homepage = "http://matiq.com"
|
18
|
+
s.license = "MIT"
|
19
|
+
s.platform = Gem::Platform::RUBY
|
18
20
|
|
19
|
-
s.
|
20
|
-
s.platform = Gem::Platform::RUBY
|
21
|
+
s.metadata["source_code_uri"] = "https://github.com/matique/formie"
|
21
22
|
|
22
|
-
s.files
|
23
|
-
s.
|
24
|
-
s.require_paths = ['lib']
|
23
|
+
s.files = `git ls-files -z`.split("\x0")
|
24
|
+
s.require_paths = ["lib"]
|
25
25
|
|
26
|
-
s.add_development_dependency
|
27
|
-
s.add_development_dependency
|
28
|
-
s.add_development_dependency
|
29
|
-
s.add_development_dependency
|
26
|
+
s.add_development_dependency "bundler"
|
27
|
+
s.add_development_dependency "rake"
|
28
|
+
s.add_development_dependency "appraisal"
|
29
|
+
s.add_development_dependency "combustion"
|
30
30
|
|
31
|
-
s.add_development_dependency
|
32
|
-
s.add_development_dependency
|
31
|
+
s.add_development_dependency "minitest"
|
32
|
+
s.add_development_dependency "sqlite3"
|
33
33
|
end
|
@@ -2,15 +2,17 @@
|
|
2
2
|
|
3
3
|
source "https://rubygems.org"
|
4
4
|
|
5
|
-
gem "rails", "~>
|
5
|
+
gem "rails", "~> 6.1"
|
6
|
+
gem "dryer-config", "~> 6.0"
|
6
7
|
|
7
8
|
group :test do
|
9
|
+
gem "capybara"
|
8
10
|
gem "observr"
|
11
|
+
gem "ricecream"
|
12
|
+
gem "rubocop", require: false
|
9
13
|
gem "simplecov", require: false
|
10
|
-
gem "minitest"
|
11
|
-
gem "capybara"
|
12
|
-
gem "sqlite3", "!= 1.4.0"
|
13
14
|
gem "slim"
|
15
|
+
gem "spring"
|
14
16
|
end
|
15
17
|
|
16
18
|
gemspec path: "../"
|
@@ -2,15 +2,17 @@
|
|
2
2
|
|
3
3
|
source "https://rubygems.org"
|
4
4
|
|
5
|
-
gem "rails", "~>
|
5
|
+
gem "rails", "~> 7.0"
|
6
|
+
gem "dryer-config", "~> 7.0"
|
6
7
|
|
7
8
|
group :test do
|
9
|
+
gem "capybara"
|
8
10
|
gem "observr"
|
11
|
+
gem "ricecream"
|
12
|
+
gem "rubocop", require: false
|
9
13
|
gem "simplecov", require: false
|
10
|
-
gem "minitest"
|
11
|
-
gem "capybara"
|
12
|
-
gem "sqlite3", "!= 1.4.0"
|
13
14
|
gem "slim"
|
15
|
+
gem "spring"
|
14
16
|
end
|
15
17
|
|
16
18
|
gemspec path: "../"
|
data/lib/formie/version.rb
CHANGED
@@ -1,12 +1,10 @@
|
|
1
1
|
# rubocop: disable all
|
2
2
|
|
3
3
|
module Formie
|
4
|
-
VERSION =
|
5
|
-
# VERSION =
|
6
|
-
# VERSION =
|
7
|
-
# VERSION =
|
8
|
-
# VERSION =
|
9
|
-
# VERSION =
|
10
|
-
# VERSION = '0.9.14' # 2019-03-02
|
11
|
-
# VERSION = '0.9.13'
|
4
|
+
VERSION = "1.1.0" # 2022-12-18
|
5
|
+
# VERSION = "1.0.4" # 2021-06-20
|
6
|
+
# VERSION = "1.0.3" # 2020-07-23
|
7
|
+
# VERSION = "1.0.0" # 2019-09-26
|
8
|
+
# VERSION = "0.9.16" # 2019-03-05
|
9
|
+
# VERSION = "0.9.14" # 2019-03-02
|
12
10
|
end
|
data/lib/formie.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "formie/engine"
|
4
4
|
|
5
5
|
module Formie
|
6
6
|
Rails6 = Rails.version.to_f >= 6.0
|
7
|
-
PATH = Rails6 ?
|
7
|
+
PATH = Rails6 ? "app/views/formies" : "app/formies"
|
8
8
|
|
9
9
|
def self.reload
|
10
10
|
if Rails6 && !File.directory?("#{Rails.root}/app/views/formies")
|
@@ -14,8 +14,8 @@ module Formie
|
|
14
14
|
now = Time.now
|
15
15
|
@last_update ||= Time.new(0)
|
16
16
|
load_formies(::ActionView::Helpers::FormBuilder, "#{PATH}/forms")
|
17
|
-
load_formies(::ActionView::Helpers::TextHelper,
|
18
|
-
load_formies(::ActionView::Helpers::TextHelper,
|
17
|
+
load_formies(::ActionView::Helpers::TextHelper, "#{PATH}/application")
|
18
|
+
load_formies(::ActionView::Helpers::TextHelper, "#{PATH}/templates")
|
19
19
|
@last_update = now
|
20
20
|
end
|
21
21
|
|
@@ -27,15 +27,15 @@ module Formie
|
|
27
27
|
params = args.extract_options!
|
28
28
|
options = {}
|
29
29
|
if Rails6
|
30
|
-
options[:template] = path.sub("#{Rails.root}/app/views",
|
30
|
+
options[:template] = path.sub("#{Rails.root}/app/views", "")
|
31
31
|
else
|
32
32
|
options[:file] = path
|
33
33
|
end
|
34
34
|
options[:locals] = {}
|
35
35
|
options[:locals].update params
|
36
36
|
options[:locals].update formiename: formiename,
|
37
|
-
|
38
|
-
if defined?(controller) ==
|
37
|
+
block: block, form: self, args: args
|
38
|
+
if defined?(controller) == "method" &&
|
39
39
|
controller.respond_to?(:render_to_body) # credits to MARS
|
40
40
|
controller.render_to_body(options)
|
41
41
|
else
|
@@ -51,8 +51,8 @@ module Formie
|
|
51
51
|
return unless File.exist?(dir)
|
52
52
|
|
53
53
|
hsh = {}
|
54
|
-
Dir.glob(File.join(dir,
|
55
|
-
base = File.basename(path).split(
|
54
|
+
Dir.glob(File.join(dir, "**", "**")).sort.each { |path|
|
55
|
+
base = File.basename(path).split(".").first
|
56
56
|
hsh[base] = path unless hsh[base]
|
57
57
|
}
|
58
58
|
hsh.each { |name, path|
|
@@ -1,16 +1,14 @@
|
|
1
|
-
require
|
1
|
+
require "test_helper"
|
2
2
|
|
3
3
|
class OrdersControllerTest < ActionController::TestCase
|
4
|
-
|
5
|
-
test 'checking formie copyright' do
|
4
|
+
test "formie copyright" do
|
6
5
|
get :index
|
7
6
|
assert_response :success
|
8
|
-
# assert_not_nil assigns(:orders)
|
7
|
+
# assert_not_nil assigns(:orders)
|
9
8
|
assert_match(/copyright/, response.body)
|
10
9
|
assert_match(/Copyright/, response.body)
|
11
|
-
assert_match(/label
|
12
|
-
assert_match(/input
|
13
|
-
assert_match(/def
|
10
|
+
assert_match(/label/, response.body)
|
11
|
+
assert_match(/input/, response.body)
|
12
|
+
assert_match(/def/, response.body)
|
14
13
|
end
|
15
|
-
|
16
14
|
end
|
@@ -1,36 +1,40 @@
|
|
1
1
|
# http://blog.crowdint.com/2013/06/14/testing-rails-with-minitest.html
|
2
2
|
|
3
|
-
require
|
3
|
+
require "test_helper"
|
4
4
|
|
5
5
|
describe "Formie" do
|
6
6
|
include Capybara::DSL
|
7
7
|
|
8
8
|
before do
|
9
9
|
Order.delete_all
|
10
|
-
Order.create :
|
10
|
+
Order.create name: "Rumpelstilzchen"
|
11
11
|
end
|
12
12
|
|
13
|
-
it
|
13
|
+
it "should display copyright" do
|
14
14
|
visit "/orders"
|
15
|
-
assert page.has_content?(
|
15
|
+
assert page.has_content?("Copyright")
|
16
16
|
end
|
17
17
|
|
18
|
-
it
|
18
|
+
it "should list one order" do
|
19
19
|
order = Order.all.first
|
20
20
|
|
21
21
|
visit "/orders/#{order.id}"
|
22
|
-
|
23
|
-
|
22
|
+
# using form_with:
|
23
|
+
fnd = 'form p input[name="order[name]"]'
|
24
|
+
assert_equal order.name, page.find(fnd).value
|
25
|
+
# using form_for:
|
26
|
+
# assert_equal order.name, page.find("form p input#order_name").value
|
27
|
+
assert_equal "Hello Slim", page.find("form span").text
|
24
28
|
end
|
25
29
|
|
26
|
-
it
|
30
|
+
it "should remove comments in Slim testing full stack" do
|
27
31
|
order = Order.all.first
|
28
32
|
|
29
33
|
visit "/orders/#{order.id}"
|
30
34
|
refute page.has_content?("a comment")
|
31
35
|
end
|
32
36
|
|
33
|
-
it
|
37
|
+
it "builtins" do
|
34
38
|
visit "/orders/new"
|
35
39
|
assert page.has_content?("action_name new")
|
36
40
|
assert page.has_content?("args [123, 456]")
|
@@ -40,5 +44,4 @@ describe "Formie" do
|
|
40
44
|
assert page.has_content?("form.object Order")
|
41
45
|
assert page.has_content?("params new")
|
42
46
|
end
|
43
|
-
|
44
47
|
end
|
@@ -1,5 +1,4 @@
|
|
1
1
|
class OrdersController < ApplicationController
|
2
|
-
|
3
2
|
def index
|
4
3
|
@orders = Order.all
|
5
4
|
end
|
@@ -9,8 +8,7 @@ class OrdersController < ApplicationController
|
|
9
8
|
end
|
10
9
|
|
11
10
|
def show
|
12
|
-
Order.create :
|
11
|
+
Order.create name: "hugo"
|
13
12
|
@order = Order.find(params[:id])
|
14
13
|
end
|
15
|
-
|
16
14
|
end
|
data/test/internal/db/schema.rb
CHANGED
@@ -1,10 +1,8 @@
|
|
1
1
|
ActiveRecord::Schema.define(version: 20141016161801) do
|
2
|
-
|
3
2
|
create_table "orders", force: true do |t|
|
4
|
-
t.string
|
5
|
-
t.string
|
3
|
+
t.string "name"
|
4
|
+
t.string "qty"
|
6
5
|
t.datetime "created_at", null: false
|
7
6
|
t.datetime "updated_at", null: false
|
8
7
|
end
|
9
|
-
|
10
8
|
end
|
data/test/test_helper.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
if ENV[
|
2
|
-
require
|
1
|
+
if ENV["COVERAGE"]
|
2
|
+
require "simplecov"
|
3
3
|
SimpleCov.start do
|
4
|
-
add_filter
|
4
|
+
add_filter "/test/"
|
5
5
|
end
|
6
6
|
end
|
7
7
|
|
@@ -9,7 +9,7 @@ require "combustion"
|
|
9
9
|
Combustion.path = "test/internal"
|
10
10
|
Combustion.initialize! :active_record
|
11
11
|
|
12
|
-
require
|
13
|
-
require
|
14
|
-
require
|
15
|
-
require
|
12
|
+
require "rails/test_help"
|
13
|
+
require "minitest/autorun"
|
14
|
+
require "minitest/benchmark"
|
15
|
+
require "capybara/rails"
|