autoforme 1.10.0 → 1.11.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6f9fb399d144c4bfc7eed6e2a4f7497cab7bc25b8409d555c4f67fb91bad9bb7
4
- data.tar.gz: bffb9114ef162400c639abb1ee17b7eb42ced481294d152e2603711c01752274
3
+ metadata.gz: '0198a23636933034920c066694a4acd8e58d5529fbf21ada5f542a7de444cc2c'
4
+ data.tar.gz: 6cf1f310f06018a91573472c7410c1dda1842b7f96593a82deaf9be5f2bdd524
5
5
  SHA512:
6
- metadata.gz: 15cd700c5edc91d860dcec0209dae57dd3db48ebe2bc6cf66f19b9d786d7a51b23f909ec80a0a2333af8d9c42c165690dd6710c26ebfadfbfa93c9d17618976b
7
- data.tar.gz: 0c4a42c4e34e398209f98e85303558ef95447eb6a1e8f6351a182f214a1dab7b754f86aca8d81d35ba32d5890a09fa417a28c7e8212a2284df5d265c776533e8
6
+ metadata.gz: 8931ddb513d806df30b8a4fe36fb20583597ac4e9f45e1144c5732cff66d09f92a14967a5ac4c35724ac339bfd23af866b454490ffabe99b327dfaff2e1aa787
7
+ data.tar.gz: '097239f8074dc20537dec29064f24c2e5fbb521cf3586bb828726afc2b436eed190794d2b276e9b108c60bb6a4c3116a35dc651d54e32af5ff74d34e4a6b586e'
data/CHANGELOG CHANGED
@@ -1,3 +1,11 @@
1
+ === 1.11.0 (2021-11-30)
2
+
3
+ * Require forme 2.0.0 (jeremyevans)
4
+
5
+ * Add support for view_options framework option (nmb, jeremyevans) (#42)
6
+
7
+ * Drop support for Ruby 1.8 (jeremyevans)
8
+
1
9
  === 1.10.0 (2021-08-27)
2
10
 
3
11
  * Do not consider read_only many_to_many associations to be editable (jeremyevans)
data/README.rdoc CHANGED
@@ -174,6 +174,8 @@ page_header :: Override the default header used for pages
174
174
  show_html :: The html to use for displaying the value for an object field. Should be a proc that takes the
175
175
  model object, column symbol, type symbol, and request and returns the html to use.
176
176
  table_class :: The html class string to use for the browse and search tables
177
+ view_options :: Hash with options passed when rendering the view (how these options are used varies
178
+ in each of the supported web frameworks), e.g. <tt>view_options: {:layout => :formelayout}</tt>
177
179
 
178
180
  These hook options should be callable objects that are called with the model object and the request.
179
181
 
@@ -227,10 +227,15 @@ module AutoForme
227
227
  # Options to use for the form. If the form uses POST, automatically adds the CSRF token.
228
228
  def form_opts(action=nil)
229
229
  opts = model.form_options_for(type, request).dup
230
- hidden_tags = opts[:hidden_tags] = []
231
- if csrf = request.csrf_token_hash(action)
232
- hidden_tags << lambda{|tag| csrf if (tag.attr[:method] || tag.attr['method']).to_s.upcase == 'POST'}
230
+
231
+ opts[:_before_post] = lambda do |form|
232
+ if csrf_hash = request.csrf_token_hash(action)
233
+ csrf_hash.each do |name, value|
234
+ form.tag(:input, :type=>:hidden, :name=>name, :value=>value)
235
+ end
236
+ end
233
237
  end
238
+
234
239
  opts
235
240
  end
236
241
 
@@ -58,7 +58,11 @@ module AutoForme
58
58
  elsif @autoforme_action.request.xhr?
59
59
  render :html=>@autoforme_text.html_safe
60
60
  else
61
- render :inline=>"<%=raw @autoforme_text %>", :layout=>true
61
+ opts = framework.opts[:view_options]
62
+ opts = opts ? opts.dup : {}
63
+ opts[:layout] = true unless opts.has_key?(:layout)
64
+ opts[:inline] = "<%=raw @autoforme_text %>"
65
+ render opts
62
66
  end
63
67
  else
64
68
  render :plain=>'Unhandled Request', :status=>404
@@ -53,16 +53,18 @@ module AutoForme
53
53
  def csrf_token_hash(action=nil)
54
54
  if @controller.respond_to?(:check_csrf!)
55
55
  # Using route_csrf plugin
56
- # :nocov:
57
56
  token = if @controller.use_request_specific_csrf_tokens?
58
57
  @controller.csrf_token(@controller.csrf_path(action))
58
+ # :nocov:
59
59
  else
60
60
  @controller.csrf_token
61
+ # :nocov:
61
62
  end
62
63
  {@controller.csrf_field=>token}
63
64
  # :nocov:
64
65
  elsif defined?(::Rack::Csrf)
65
66
  {::Rack::Csrf.field=>::Rack::Csrf.token(@env)}
67
+ # :nocov:
66
68
  end
67
69
  end
68
70
 
@@ -106,7 +108,10 @@ module AutoForme
106
108
  elsif @autoforme_action.request.xhr?
107
109
  @autoforme_text
108
110
  else
109
- view(:content=>@autoforme_text)
111
+ opts = framework.opts[:view_options]
112
+ opts = opts ? opts.dup : {}
113
+ opts[:content] = @autoforme_text
114
+ view(opts)
110
115
  end
111
116
  end
112
117
  end
@@ -50,7 +50,9 @@ module AutoForme
50
50
  elsif @autoforme_action.request.xhr?
51
51
  @autoforme_text
52
52
  else
53
- erb "<%= @autoforme_text %>".dup
53
+ opts = framework.opts[:view_options]
54
+ opts = opts ? opts.dup : {}
55
+ erb("<%= @autoforme_text %>".dup, opts ? opts.dup : {})
54
56
  end
55
57
  else
56
58
  pass
@@ -316,6 +316,12 @@ module AutoForme
316
316
  model.db.transaction(:savepoint=>true){obj.send(meth, ret)}
317
317
  rescue S::UniqueConstraintViolation
318
318
  # Already added, safe to ignore
319
+ rescue S::ConstraintViolation
320
+ # Old versions of sqlite3 and jdbc-sqlite3 can raise generic
321
+ # ConstraintViolation instead of UniqueConstraintViolation
322
+ # :nocov:
323
+ raise unless model.db.database_type == :sqlite
324
+ # :nocov:
319
325
  end
320
326
  end
321
327
  end
@@ -6,7 +6,7 @@ module AutoForme
6
6
  MAJOR = 1
7
7
 
8
8
  # The minor version of AutoForme, updated for new feature releases of AutoForme.
9
- MINOR = 10
9
+ MINOR = 11
10
10
 
11
11
  # The patch version of AutoForme, updated only for bug fixes from the last
12
12
  # feature release.
data/lib/autoforme.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  # frozen-string-literal: true
2
2
 
3
3
  require 'forme'
4
- require 'thread'
5
4
  require 'rack/utils'
6
5
 
7
6
  module AutoForme
@@ -50,10 +49,10 @@ module AutoForme
50
49
  end
51
50
  end
52
51
 
53
- require 'autoforme/opts_attributes'
54
- require 'autoforme/model'
55
- require 'autoforme/framework'
56
- require 'autoforme/request'
57
- require 'autoforme/action'
58
- require 'autoforme/table'
59
- require 'autoforme/version'
52
+ require_relative 'autoforme/opts_attributes'
53
+ require_relative 'autoforme/model'
54
+ require_relative 'autoforme/framework'
55
+ require_relative 'autoforme/request'
56
+ require_relative 'autoforme/action'
57
+ require_relative 'autoforme/table'
58
+ require_relative 'autoforme/version'
@@ -1,6 +1,6 @@
1
1
  # frozen-string-literal: true
2
2
 
3
- require 'autoforme'
3
+ require_relative '../../autoforme'
4
4
 
5
5
  class Roda
6
6
  module RodaPlugins
data/spec/all.rb CHANGED
@@ -1,2 +1,2 @@
1
1
  puts "Running specs with #{ENV['FRAMEWORK']||'roda'} framework"
2
- Dir['./spec/*_spec.rb'].each{|f| require f}
2
+ Dir.new(File.dirname(__FILE__)).each{|f| require_relative f if f.end_with?('_spec.rb')}
@@ -1,4 +1,4 @@
1
- require './spec/spec_helper'
1
+ require_relative 'spec_helper'
2
2
 
3
3
  describe AutoForme do
4
4
  before(:all) do
data/spec/basic_spec.rb CHANGED
@@ -1,4 +1,4 @@
1
- require './spec/spec_helper'
1
+ require_relative 'spec_helper'
2
2
 
3
3
  describe AutoForme do
4
4
  before(:all) do
@@ -12,6 +12,7 @@ describe AutoForme do
12
12
  it "should have basic functionality working" do
13
13
  app_setup(Artist)
14
14
  visit("/Artist/new")
15
+ page.html.must_include '<!DOCTYPE html>'
15
16
  page.title.must_equal 'Artist - New'
16
17
  fill_in 'Name', :with=>'TestArtistNew'
17
18
  click_button 'Create'
@@ -607,6 +608,13 @@ describe AutoForme do
607
608
  page.html.must_match(/Name.+TestArtistUpdate/m)
608
609
  page.current_path.must_match %r{/Artist/edit/\d+}
609
610
  end
611
+
612
+ it "should support view_options" do
613
+ app_setup(Artist, view_options: {:layout=>false}){}
614
+ visit("/Artist/browse")
615
+ page.html.wont_include '<!DOCTYPE html>'
616
+ page.all('table').first['id'].must_equal 'autoforme_table'
617
+ end
610
618
  end
611
619
 
612
620
  describe AutoForme do
data/spec/mtm_spec.rb CHANGED
@@ -1,4 +1,4 @@
1
- require './spec/spec_helper'
1
+ require_relative 'spec_helper'
2
2
 
3
3
  describe AutoForme do
4
4
  before(:all) do
@@ -595,7 +595,7 @@ describe AutoForme do
595
595
  end
596
596
 
597
597
  visit("/Artist/new")
598
- page.html.wont_include 'MTM'
598
+ page.html.wont_include 'Artist/mtm_edit'
599
599
  fill_in 'Name', :with=>'Artist1'
600
600
  click_button 'Create'
601
601
  click_link 'Edit'
@@ -607,7 +607,7 @@ describe AutoForme do
607
607
  page.html.must_include 'Unhandled Request'
608
608
 
609
609
  visit("/Album/new")
610
- page.html.wont_include 'MTM'
610
+ page.html.wont_include 'Album/mtm_edit'
611
611
  fill_in 'Name', :with=>'Album1'
612
612
  click_button 'Create'
613
613
  click_link 'Edit'
@@ -1,7 +1,6 @@
1
- require 'rubygems'
2
1
  require 'rails'
3
2
  require 'action_controller/railtie'
4
- require 'autoforme'
3
+ require_relative '../lib/autoforme'
5
4
 
6
5
  class AutoFormeSpec::App
7
6
  class << self
@@ -78,12 +77,11 @@ HTML
78
77
  # Work around issue in backported openssl environments where
79
78
  # secret is 64 bytes intead of 32 bytes
80
79
  require 'active_support/message_encryptor'
81
- ActiveSupport::MessageEncryptor.send :prepend, Module.new {
82
- def initialize(secret, *signature_key_or_options)
83
- secret = secret[0, 32]
84
- super
85
- end
86
- }
80
+ def (ActiveSupport::MessageEncryptor).new(secret, *signature_key_or_options)
81
+ obj = allocate
82
+ obj.send(:initialize, secret[0, 32], *signature_key_or_options)
83
+ obj
84
+ end
87
85
  end
88
86
  if Rails.version > '4.2'
89
87
  config.action_dispatch.cookies_serializer = :json
@@ -91,6 +89,7 @@ HTML
91
89
  if Rails.version > '5'
92
90
  # Force Rails to dispatch to correct controller
93
91
  ActionDispatch::Routing::RouteSet::Dispatcher.class_eval do
92
+ alias controller controller
94
93
  define_method(:controller){|_| controller}
95
94
  end
96
95
  config.session_store :cookie_store, :key=>'_autoforme_test_session'
data/spec/roda_spec.rb CHANGED
@@ -1,4 +1,4 @@
1
- require './spec/spec_helper'
1
+ require_relative 'spec_helper'
2
2
 
3
3
  describe AutoForme do
4
4
  before(:all) do
@@ -1,6 +1,5 @@
1
- require 'rubygems'
2
1
  require 'roda'
3
- require 'autoforme'
2
+ require_relative '../lib/autoforme'
4
3
  require 'rack/csrf'
5
4
 
6
5
  begin
@@ -1,4 +1,3 @@
1
- require 'rubygems'
2
1
  require 'sequel'
3
2
  require 'logger'
4
3
 
@@ -1,6 +1,5 @@
1
- require 'rubygems'
2
1
  require 'sinatra/base'
3
- require 'autoforme'
2
+ require_relative '../lib/autoforme'
4
3
  require 'sinatra/flash'
5
4
  require 'rack/csrf'
6
5
 
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,3 @@
1
- require 'rubygems'
2
1
  $: << File.expand_path(File.join(__FILE__, '../../lib'))
3
2
  ENV['FRAMEWORK'] ||= 'roda'
4
3
 
@@ -19,7 +18,7 @@ if ENV['COVERAGE']
19
18
  end
20
19
  end
21
20
 
22
- require "./spec/#{ENV['FRAMEWORK']}_spec_helper"
21
+ require_relative "#{ENV['FRAMEWORK']}_spec_helper"
23
22
 
24
23
  require 'capybara'
25
24
  require 'capybara/dsl'
@@ -35,7 +34,7 @@ if ENV['WARNING']
35
34
  Warning.ignore([:missing_ivar, :fixnum, :not_reached])
36
35
  end
37
36
 
38
- require './spec/sequel_spec_helper'
37
+ require_relative 'sequel_spec_helper'
39
38
 
40
39
  class Minitest::HooksSpec
41
40
  include Rack::Test::Methods
data/spec/unit_spec.rb CHANGED
@@ -1,4 +1,4 @@
1
- require './spec/spec_helper'
1
+ require_relative 'spec_helper'
2
2
 
3
3
  describe AutoForme do
4
4
  before(:all) do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: autoforme
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.10.0
4
+ version: 1.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Evans
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-27 00:00:00.000000000 Z
11
+ date: 2021-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: forme
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 1.6.0
19
+ version: 2.0.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 1.6.0
26
+ version: 2.0.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rack
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -278,14 +278,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
278
278
  requirements:
279
279
  - - ">="
280
280
  - !ruby/object:Gem::Version
281
- version: '0'
281
+ version: 1.9.2
282
282
  required_rubygems_version: !ruby/object:Gem::Requirement
283
283
  requirements:
284
284
  - - ">="
285
285
  - !ruby/object:Gem::Version
286
286
  version: '0'
287
287
  requirements: []
288
- rubygems_version: 3.2.22
288
+ rubygems_version: 3.2.32
289
289
  signing_key:
290
290
  specification_version: 4
291
291
  summary: Web Administrative Console for Roda/Sinatra/Rails and Sequel::Model