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.
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
- Formie
2
- ======
1
+ # Formie
3
2
 
4
3
  [![Gem Version](https://badge.fury.io/rb/formie.svg)](https://badge.fury.io/rb/formie)
5
- [![Build Status](https://travis-ci.org/matique/formie.svg?branch=master)](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
- $ [sudo] gem install formie
25
-
26
- or:
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 form_for (similar to fields_for))
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
- # app/controllers/application_controller.rb
57
+ ```ruby
58
+ # app/controllers/application_controller.rb
65
59
 
66
- before_filter do
67
- Formie.reload if Rails.env.development?
68
- end
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
- <%= copyright %>
74
- <%= back %>
75
- <%= show obj: @order %>
68
+ ```ruby
69
+ <%= copyright %>
70
+ <%= back %>
71
+ <%= show obj: @order %>
76
72
 
77
- <%= form_for @order do |f| %>
78
- <%= f.l_text_field :who %>
79
- <%= f.l_text_field :amount %>
80
- <% end %>
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
- # application/copyright.html.erb
85
- <div class="copyright"> Copyright (c) 2009 </div>
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
- # application/back.html.erb
88
- <a href="<%= "/#{h(controller_name)}" %>"> Back </a>
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
- # application/show.html.erb
91
- <a href="<%= "/#{h(controller_name)}/#{obj.id}" %>"> Show </a>
98
+ # templates/hello.slim
99
+ / a comment
92
100
 
93
- # forms/l_text_field.html.erb
94
- <% field = args.first %>
95
- <p>
96
- <%= form.label field %><br />
97
- <%= form.text_field field %>
98
- </p>
101
+ span Hello Slim
102
+ ```
99
103
 
100
- # templates/hello.slim
101
- / a comment
104
+ ## Miscellaneous
102
105
 
103
- span Hello Slim
106
+ Copyright (c) 2009-2022 Dittmar Krall (www.matiq.com),
107
+ released under the MIT license:
104
108
 
105
- Copyright (c) 2009-2019 Dittmar Krall, released under the MIT license.
109
+ * https://opensource.org/licenses/MIT
data/Rakefile CHANGED
@@ -1,10 +1,10 @@
1
- require 'rake/testtask'
1
+ require "rake/testtask"
2
2
 
3
- desc 'Run the tests.'
3
+ desc "Run the tests."
4
4
  Rake::TestTask.new do |t|
5
- t.libs << 'lib'
6
- t.libs << 'test'
7
- t.pattern = 'test/**/*_test.rb'
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('../lib', __FILE__)
1
+ lib = File.expand_path("../lib", __FILE__)
2
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require 'formie/version'
3
+ require "formie/version"
4
4
 
5
5
  Gem::Specification.new do |s|
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.'
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 = ['Dittmar Krall']
16
- s.email = ['dittmar.krall@matique.de']
17
- s.homepage = 'http://matique.de'
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.license = 'MIT'
20
- s.platform = Gem::Platform::RUBY
21
+ s.metadata["source_code_uri"] = "https://github.com/matique/formie"
21
22
 
22
- s.files = `git ls-files -z`.split("\x0")
23
- s.test_files = s.files.grep(%r{^(test|spec|features)/})
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 'bundler'
27
- s.add_development_dependency 'rake', '~> 13'
28
- s.add_development_dependency 'appraisal', '~> 2'
29
- s.add_development_dependency 'combustion', '~> 1.1'
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 'minitest', '~> 5'
32
- s.add_development_dependency 'sqlite3', '~> 1'
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.1"
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.0.0"
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: "../"
@@ -1,12 +1,10 @@
1
1
  # rubocop: disable all
2
2
 
3
3
  module Formie
4
- VERSION = '1.0.3' # 2020-07-23
5
- # VERSION = '1.0.2' # 2020-07-14
6
- # VERSION = '1.0.1' # 2020-04-27
7
- # VERSION = '1.0.0' # 2019-09-26
8
- # VERSION = '0.9.16' # 2019-03-05
9
- # VERSION = '0.9.15' # 2019-03-02
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 'formie/engine'
3
+ require "formie/engine"
4
4
 
5
5
  module Formie
6
6
  Rails6 = Rails.version.to_f >= 6.0
7
- PATH = Rails6 ? 'app/views/formies' : 'app/formies'
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, "#{PATH}/application")
18
- load_formies(::ActionView::Helpers::TextHelper, "#{PATH}/templates")
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
- block: block, form: self, args: args
38
- if defined?(controller) == 'method' &&
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, '**', '**')).sort.each { |path|
55
- base = File.basename(path).split('.').first
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 'test_helper'
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/ , response.body)
12
- assert_match(/input/ , response.body)
13
- assert_match(/def/ , response.body)
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 'test_helper'
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 :name => 'Rumpelstilzchen'
10
+ Order.create name: "Rumpelstilzchen"
11
11
  end
12
12
 
13
- it 'should display copyright' do
13
+ it "should display copyright" do
14
14
  visit "/orders"
15
- assert page.has_content?('Copyright')
15
+ assert page.has_content?("Copyright")
16
16
  end
17
17
 
18
- it 'should list one order' do
18
+ it "should list one order" do
19
19
  order = Order.all.first
20
20
 
21
21
  visit "/orders/#{order.id}"
22
- assert_equal order.name, page.find('form p input#order_name').value
23
- assert_equal 'Hello Slim', page.find('form span').text
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 'should remove comments in Slim testing full stack' do
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 'builtins' do
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
@@ -2,7 +2,6 @@ class ApplicationController < ActionController::Base
2
2
  protect_from_forgery with: :exception
3
3
 
4
4
  before_action do
5
- Formie.reload if 'development' == Rails.env
5
+ Formie.reload if Rails.env == "development"
6
6
  end
7
-
8
7
  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 :name => 'hugo'
11
+ Order.create name: "hugo"
13
12
  @order = Order.find(params[:id])
14
13
  end
15
-
16
14
  end
@@ -1,7 +1,5 @@
1
1
  class Order < ApplicationRecord
2
-
3
2
  before_save do |row|
4
- row.errors.add :base, 'panic' if row.name == 'error'
3
+ row.errors.add :base, "panic" if row.name == "error"
5
4
  end
6
-
7
5
  end
@@ -1,3 +1,3 @@
1
- <%= form_for @order do |f| %>
1
+ <%= form_with model: @order, class: Order do |f| %>
2
2
  <%= render 'new', :f => f %>
3
3
  <% end %>
@@ -1,3 +1,3 @@
1
- <%= form_for @order do |f| %>
1
+ <%= form_with model: @order do |f| %>
2
2
  <%= render 'form', :f => f %>
3
3
  <% end %>
@@ -1,4 +1,4 @@
1
1
  Rails.application.routes.draw do
2
2
  resources :orders
3
- root :to => 'orders#index'
3
+ root to: "orders#index"
4
4
  end
@@ -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 "name"
5
- t.string "qty"
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['COVERAGE']
2
- require 'simplecov'
1
+ if ENV["COVERAGE"]
2
+ require "simplecov"
3
3
  SimpleCov.start do
4
- add_filter '/test/'
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 'rails/test_help'
13
- require 'minitest/autorun'
14
- require 'minitest/benchmark'
15
- require 'capybara/rails'
12
+ require "rails/test_help"
13
+ require "minitest/autorun"
14
+ require "minitest/benchmark"
15
+ require "capybara/rails"