autoforme 0.5.5 → 1.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 283e6c9e679c9f6c6dde910bfa00561659817393
4
- data.tar.gz: d79eb131e43fd1163ba8c90f326e8e9da67b5eff
3
+ metadata.gz: 86f7ea431b13b17ae2f2c67a5051e58ed8f6bab8
4
+ data.tar.gz: 01fa45ac012900a4bebee2730aa8a415a88b0184
5
5
  SHA512:
6
- metadata.gz: ee0211132bcd27e7f0797cdc030ce6329a3af5766b73e33aa8b83e383243f27059997a4eca5e3ce41f4d64d8ed1b032565063e72e7bc86e9f4c33ddf54a034e3
7
- data.tar.gz: c11a4b273bd6dd264faeb35ab5803e78a57095039a15becc1bf33f813225b7ad0cbc3e2948a23fdd917490ddf47199123af48f8c38fd1ce193f9b3fea4562521
6
+ metadata.gz: ad900255d457cb444dd486118f45ee7127752439c4c72292431b1d020fed40abae4cb828bd8bf22bb3199443df6df0ece873ad85a678b5822212908eb3c8a93e
7
+ data.tar.gz: 2545e4f885fad140056be830b998d88be8771b5adaf8949b5e5e4ef4e9e37bbebfdd0a41cea47fc19f6c66757e21215c5804f48f138266d76988e4c644a2603a
data/CHANGELOG CHANGED
@@ -1,3 +1,11 @@
1
+ === 1.0.0 (2014-07-30)
2
+
3
+ * Assume :sequel model type (jeremyevans)
4
+
5
+ * Work without indifferent params (jeremyevans)
6
+
7
+ * Add support for roda web framework (jeremyevans)
8
+
1
9
  === 0.5.5 (2014-04-10)
2
10
 
3
11
  * Make Models::Sequel#mtm_update compatible with Sequel 4.10+ (jeremyevans)
@@ -3,7 +3,8 @@
3
3
  AutoForme is an administrative web front end to an ORM that uses
4
4
  Forme [1] for building the HTML forms. It is designed to
5
5
  integrate easily into web frameworks, and currently supports
6
- both Sinatra and Rails.
6
+ Sinatra, Roda, and Rails. The only currently supported ORM is
7
+ Sequel::Model.
7
8
 
8
9
  AutoForme's UI and capabilities are modeled on
9
10
  scaffolding_extensions [2], though AutoForme is considerably more
@@ -14,19 +15,16 @@ flexible in terms of configuration.
14
15
 
15
16
  = Installation
16
17
 
17
- sudo gem install autoforme
18
+ gem install autoforme
18
19
 
19
- = Demo Site
20
+ = Links
20
21
 
21
- A demo site is available at http://autoforme-demo.jeremyevans.net
22
-
23
- = Documentation Site
24
-
25
- RDoc Documentation is available at http://autoforme.jeremyevans.net
26
-
27
- = Source Code
28
-
29
- Source code is available on GitHub at https://github.com/jeremyevans/autoforme
22
+ Demo Site :: http://autoforme-demo.jeremyevans.net
23
+ RDoc :: http://autoforme.jeremyevans.net
24
+ Source :: https://github.com/jeremyevans/autoforme
25
+ IRC :: irc://irc.freenode.net/forme
26
+ Google Group :: https://groups.google.com/forum/#!forum/ruby-forme
27
+ Bug Tracker :: https://github.com/jeremyevans/autoforme/issues
30
28
 
31
29
  = Features
32
30
 
@@ -40,11 +38,11 @@ Source code is available on GitHub at https://github.com/jeremyevans/autoforme
40
38
 
41
39
  = Basic Configuration
42
40
 
43
- AutoForme is configured using a fairly simple DSL. Here is an example:
41
+ AutoForme is configured using a fairly simple DSL. Here is an example
42
+ for Sinatra:
44
43
 
45
44
  class App < Sinatra::Base
46
45
  AutoForme.for(:sinatra, self) do
47
- model_type :sequel
48
46
  order [:name]
49
47
 
50
48
  model Artist do
@@ -62,9 +60,6 @@ and the controller class (either a Sinatra::Base or ActionController::Base subcl
62
60
  pass <tt>AutoForme.for</tt> a block, which is instance evaled at the framework level. This
63
61
  level sets the defaults.
64
62
 
65
- Inside the framework block, you first call model_type with a symbol representing the ORM you are
66
- using. Currently, only Sequel is supported, so this should be :sequel.
67
-
68
63
  The order call in the framework block sets the default order for all models.
69
64
 
70
65
  The model calls in the framework block take a ORM model class. As only Sequel is currently
data/Rakefile CHANGED
@@ -34,6 +34,16 @@ begin
34
34
  task :default => [:spec]
35
35
  spec_with_cov.call("spec", Dir["spec/*_spec.rb"], "Run specs with sinatra/sequel")
36
36
 
37
+ desc "Run specs with roda/sequel"
38
+ task :roda_spec do
39
+ begin
40
+ ENV['FRAMEWORK'] = 'roda'
41
+ Rake::Task[:spec].invoke
42
+ ensure
43
+ ENV.delete('FRAMEWORK')
44
+ end
45
+ end
46
+
37
47
  desc "Run specs with rails/sequel"
38
48
  task :rails_spec do
39
49
  begin
@@ -55,7 +65,6 @@ end
55
65
  RDOC_DEFAULT_OPTS = ["--quiet", "--line-numbers", "--inline-source", '--title', 'AutoForme: Web Administrative Console for Sinatra/Rails and Sequel']
56
66
 
57
67
  begin
58
- gem 'rdoc', '= 3.12.2'
59
68
  gem 'hanna-nouveau'
60
69
  RDOC_DEFAULT_OPTS.concat(['-f', 'hanna'])
61
70
  rescue Gem::LoadError
@@ -12,6 +12,7 @@ module AutoForme
12
12
  # Setup a new framework class.
13
13
  def self.setup(controller, opts, &block)
14
14
  f = new(controller, opts)
15
+ f.model_type :sequel
15
16
  f.instance_exec(&block)
16
17
  f
17
18
  end
@@ -0,0 +1,68 @@
1
+ module AutoForme
2
+ module Frameworks
3
+ class Roda < AutoForme::Framework
4
+ class Request < AutoForme::Request
5
+ def initialize(roda, path)
6
+ @controller = roda
7
+ @request = roda.request
8
+ @params = @request.params
9
+ @session = roda.session
10
+ captures = @request.captures
11
+ @env = @request.env
12
+ @method = @env['REQUEST_METHOD']
13
+ @model = captures[-2]
14
+ @action_type = captures[-1]
15
+ @path = path
16
+ @id = @params['id'] || ($1 if @env['PATH_INFO'] =~ %r{\A\/(\w+)\z})
17
+ end
18
+
19
+ # Redirect to the given path
20
+ def redirect(path)
21
+ @request.redirect(path)
22
+ end
23
+
24
+ # Whether the request is an asynchronous request
25
+ def xhr?
26
+ @env['HTTP_X_REQUESTED_WITH'] =~ /XMLHttpRequest/i
27
+ end
28
+
29
+ # Use Rack::Csrf for csrf protection if it is defined.
30
+ def csrf_token_hash
31
+ {::Rack::Csrf.field=>::Rack::Csrf.token(@env)} if defined?(::Rack::Csrf)
32
+ end
33
+ end
34
+
35
+ attr_reader :route_proc
36
+
37
+ # Return a proc that should be instance_execed in the Roda routing and
38
+ # and handles the route if it recognizes it, otherwise doing nothing.
39
+ def initialize(*)
40
+ super
41
+ framework = self
42
+
43
+ matchers = [:model, :action_type]
44
+ if framework.prefix
45
+ matchers.unshift(framework.prefix[1..-1])
46
+ end
47
+
48
+ @route_proc = lambda do
49
+ r = request
50
+ path = r.env['SCRIPT_NAME']
51
+ current_matchers = matchers.dup
52
+ current_matchers << lambda do
53
+ @autoforme_action = framework.action_for(Request.new(self, path))
54
+ end
55
+
56
+ r.on *current_matchers do
57
+ @autoforme_text = @autoforme_action.handle
58
+ opts = {:inline=>"<%= @autoforme_text %>"}
59
+ opts[:layout] = false if @autoforme_action.request.xhr?
60
+ view opts
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+
67
+ register_framework(:roda, Frameworks::Roda)
68
+ end
@@ -289,7 +289,7 @@ module AutoForme
289
289
  if association?(col)
290
290
  col = association_key(col)
291
291
  end
292
- if v = params[col]
292
+ if v = params[col.to_s]
293
293
  obj.send("#{col}=", v)
294
294
  end
295
295
  end
@@ -41,13 +41,13 @@ module AutoForme
41
41
  ds = model_class.apply_filter(:association, request, ds)
42
42
  end
43
43
 
44
- v = params[ref[:key]]
44
+ v = params[ref[:key].to_s]
45
45
  v = nil if v.to_s.strip == ''
46
46
  if v
47
47
  v = ds.first!(S.qualify(ds.model.table_name, ref.primary_key)=>v)
48
48
  end
49
49
  else
50
- v = params[col]
50
+ v = params[col.to_s]
51
51
  end
52
52
 
53
53
  obj.send("#{column}=", v)
@@ -162,7 +162,7 @@ module AutoForme
162
162
  params = request.params
163
163
  ds = apply_associated_eager(:search, request, all_dataset_for(type, request))
164
164
  columns_for(:search_form, request).each do |c|
165
- if (v = params[c]) && !v.empty?
165
+ if (v = params[c.to_s]) && !v.empty?
166
166
  if association?(c)
167
167
  ref = model.association_reflection(c)
168
168
  ads = ref.associated_dataset
@@ -1,6 +1,6 @@
1
1
  module AutoForme
2
2
  # Version constant, use <tt>AutoForme.version</tt> instead.
3
- VERSION = '0.5.5'.freeze
3
+ VERSION = '1.0.0'.freeze
4
4
 
5
5
  # Returns the version as a frozen string (e.g. '0.1.0')
6
6
  def self.version
@@ -0,0 +1,52 @@
1
+ require 'autoforme'
2
+
3
+ class Roda
4
+ module RodaPlugins
5
+ module AutoForme
6
+ # Require the render plugin, since it is required.
7
+ def self.load_dependencies(app, opts={})
8
+ app.plugin :render
9
+ end
10
+
11
+ # If a block is given, automatically setup AutoForme using
12
+ # the options and block.
13
+ def self.configure(app, opts={}, &block)
14
+ app.instance_exec do
15
+ @autoforme_routes ||= {}
16
+ if block
17
+ autoforme(opts, &block)
18
+ end
19
+ end
20
+ end
21
+
22
+ module ClassMethods
23
+ # Setup AutoForme for the given Roda class using the given
24
+ # options and block. If the :name option is given, store
25
+ # this configuration for the given name.
26
+ def autoforme(opts={}, &block)
27
+ @autoforme_routes[opts[:name]] = ::AutoForme.for(:roda, self, opts, &block).route_proc
28
+ end
29
+
30
+ # Retrieve the route proc for the named or default AutoForme.
31
+ def autoforme_route(name=nil)
32
+ @autoforme_routes[name]
33
+ end
34
+
35
+ # Copy the autoforme configurations into the subclass.
36
+ def inherited(subclass)
37
+ super
38
+ subclass.instance_variable_set(:@autoforme_routes, @autoforme_routes.dup)
39
+ end
40
+ end
41
+
42
+ module InstanceMethods
43
+ # If this route matches the named or default AutoForme route, dispatch to AutoForme.
44
+ def autoforme(name=nil)
45
+ instance_exec(&self.class.autoforme_route(name))
46
+ end
47
+ end
48
+ end
49
+
50
+ register_plugin(:autoforme, AutoForme)
51
+ end
52
+ end
@@ -548,7 +548,7 @@ describe AutoForme do
548
548
  it "should support specifying filter per type using request params" do
549
549
  app_setup(Artist) do
550
550
  filter do |ds, type, req|
551
- v = req.params[:f]
551
+ v = req.params['f']
552
552
  case type
553
553
  when :edit
554
554
  ds.where{n0 > v}
@@ -51,7 +51,6 @@ HTML
51
51
 
52
52
  AutoForme.for(:rails, self, opts) do
53
53
  framework = self
54
- model_type :sequel
55
54
  if klass
56
55
  model(klass, &block)
57
56
  elsif block
@@ -0,0 +1,56 @@
1
+ require 'rubygems'
2
+ require 'roda'
3
+ require 'autoforme'
4
+ require 'rack/csrf'
5
+
6
+ class AutoFormeSpec::App < Roda
7
+ LAYOUT = <<HTML
8
+ <!DOCTYPE html>
9
+ <html>
10
+ <head><title><%= @autoforme_action.title if @autoforme_action %></title></head>
11
+ <body>
12
+ <% if flash[:notice] %>
13
+ <div class="alert alert-success"><p><%= flash[:notice] %></p></div>
14
+ <% end %>
15
+ <% if flash[:error] %>
16
+ <div class="alert alert-error"><p><%= flash[:error] %></p></div>
17
+ <% end %>
18
+ <%= yield %>
19
+ </body></html>"
20
+ HTML
21
+
22
+ use Rack::Session::Cookie, :secret => '1'
23
+ use Rack::Csrf
24
+
25
+ plugin :render, :layout=>{:inline=>LAYOUT}
26
+ plugin :not_found do
27
+ 'Unhandled Request'
28
+ end
29
+ plugin :flash
30
+
31
+ def self.autoforme(klass=nil, opts={}, &block)
32
+ sc = Class.new(self)
33
+ framework = nil
34
+ sc.class_eval do
35
+ plugin :autoforme, opts do
36
+ framework = self
37
+ if klass
38
+ model(klass, &block)
39
+ elsif block
40
+ instance_eval(&block)
41
+ end
42
+ end
43
+
44
+ route do |r|
45
+ r.get 'session/set' do
46
+ session.merge!(r.params)
47
+ ''
48
+ end
49
+
50
+ autoforme
51
+ end
52
+ end
53
+ [sc, framework]
54
+ end
55
+ end
56
+
@@ -43,7 +43,6 @@ HTML
43
43
  sc.class_eval do
44
44
  AutoForme.for(:sinatra, self, opts) do
45
45
  framework = self
46
- model_type :sequel
47
46
  if klass
48
47
  model(klass, &block)
49
48
  elsif block
@@ -8,13 +8,7 @@ module AutoFormeSpec
8
8
  end
9
9
 
10
10
  require './spec/sequel_spec_helper'
11
-
12
- case ENV['FRAMEWORK']
13
- when 'rails'
14
- require './spec/rails_spec_helper'
15
- else
16
- require './spec/sinatra_spec_helper'
17
- end
11
+ require "./spec/#{ENV['FRAMEWORK'] || 'sinatra'}_spec_helper"
18
12
 
19
13
  RSpec::Core::ExampleGroup.class_eval do
20
14
  include Rack::Test::Methods
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: 0.5.5
4
+ version: 1.0.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: 2014-04-10 00:00:00.000000000 Z
11
+ date: 2014-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: forme
@@ -80,6 +80,7 @@ files:
80
80
  - lib/autoforme/action.rb
81
81
  - lib/autoforme/framework.rb
82
82
  - lib/autoforme/frameworks/rails.rb
83
+ - lib/autoforme/frameworks/roda.rb
83
84
  - lib/autoforme/frameworks/sinatra.rb
84
85
  - lib/autoforme/model.rb
85
86
  - lib/autoforme/models/sequel.rb
@@ -87,10 +88,12 @@ files:
87
88
  - lib/autoforme/request.rb
88
89
  - lib/autoforme/table.rb
89
90
  - lib/autoforme/version.rb
91
+ - lib/roda/plugins/autoforme.rb
90
92
  - spec/associations_spec.rb
91
93
  - spec/basic_spec.rb
92
94
  - spec/mtm_spec.rb
93
95
  - spec/rails_spec_helper.rb
96
+ - spec/roda_spec_helper.rb
94
97
  - spec/sequel_spec_helper.rb
95
98
  - spec/sinatra_spec_helper.rb
96
99
  - spec/spec_helper.rb