scaffolding_extensions 1.3.1 → 1.3.2

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 CHANGED
@@ -22,13 +22,13 @@ Scaffolding Extensions currently supports:
22
22
 
23
23
  * Web Frameworks
24
24
  * Rails 2.2.2
25
- * Ramaze 2008.11
25
+ * Ramaze 2009.01
26
26
  * Camping 1.5
27
- * Sinatra 0.3.2
27
+ * Sinatra 0.9.0.4
28
28
  * Merb 1.0.4
29
29
  * Object/Relational Mappers
30
30
  * ActiveRecord 2.2.2
31
- * Sequel 2.8.0
31
+ * Sequel 2.9.0
32
32
  * Javascript Libaries (used for Ajax/Autocompleting)
33
33
  * Prototype 1.6.0.1
34
34
  * JQuery 1.2.3
data/doc/sinatra.txt CHANGED
@@ -12,9 +12,22 @@ To use the plugin if installing the gem:
12
12
 
13
13
  require 'scaffolding_extensions'
14
14
 
15
- To use the plugin, just call one of the root level scaffold methods with the
16
- path at which you want the plugin mounted:
15
+ To use the plugin, call one of the scaffold methods inside a Sinatra::Base
16
+ subclass:
17
17
 
18
- scaffold '/admin', Model1
19
- scaffold_habtm '/admin', Model1, :things
20
- scaffold_all_models '/admin', :only=>[Model1, Model2, Model3]
18
+ class Scaf < Sinatra::Base
19
+ scaffold Model1
20
+ scaffold_habtm Model1, :things
21
+ scaffold_all_models :only=>[Model1, Model2, Model3]
22
+ end
23
+
24
+ As this is going to add paths directly to where Scaf is mounted, you generally
25
+ are going to want to mount Scaf at a subpath and build and run you own Rack app:
26
+
27
+ app = Rack::Builder.app do
28
+ map("/"){run MainApp}
29
+ map("/admin"){run Scaf}
30
+ end
31
+ Rack::Handler.get('mongrel').run(app, :Host=>'0.0.0.0', :Port=>7976) do |server|
32
+ trap(:INT){server.stop}
33
+ end
@@ -50,11 +50,11 @@ module ScaffoldingExtensions
50
50
  @scaffold_class ||= @scaffold_options[:class]
51
51
  if render_options.include?(:inline)
52
52
  use_js = @scaffold_javascript
53
- headers('Content-Type'=>'text/javascript') if use_js
53
+ response['Content-Type'] = 'text/javascript' if use_js
54
54
  render(:erb, scaffold_fix_template(render_options[:inline]), :layout=>false)
55
55
  else
56
- template = resolve_template(:erb, suffix_action.to_sym, render_options, false) || scaffold_fix_template(File.read(scaffold_path(action)))
57
- layout = determine_layout(:erb, :layout, {}) || scaffold_fix_template(File.read(scaffold_path('layout'))).gsub('@content', 'yield')
56
+ template = lookup_template(:erb, suffix_action.to_sym, render_options) rescue scaffold_fix_template(File.read(scaffold_path(action)))
57
+ layout, _ = lookup_layout(:erb, render_options) || [scaffold_fix_template(File.read(scaffold_path('layout'))).gsub('@content', 'yield'), nil]
58
58
  render(:erb, template, :layout=>layout)
59
59
  end
60
60
  end
@@ -76,17 +76,7 @@ module ScaffoldingExtensions
76
76
  end
77
77
 
78
78
  def scaffold_request_param(v)
79
- sparams = params
80
- unless param = sparams[v.to_sym]
81
- param = {}
82
- sparams.each do |k,value|
83
- if match = /#{v}\[([^\]]+)\]/.match(k.to_s)
84
- param[match[1]] = value
85
- end
86
- end
87
- param = nil if param.empty?
88
- end
89
- param
79
+ params[v]
90
80
  end
91
81
 
92
82
  # You need to enable Sinatra's session support for this to work,
@@ -108,49 +98,33 @@ module ScaffoldingExtensions
108
98
  "#{@scaffold_path}/#{action}#{id}"
109
99
  end
110
100
  end
111
- end
112
-
113
- class Sinatra::EventContext
114
- SCAFFOLD_ROOTS = []
115
- extend ScaffoldingExtensions::MetaController
116
101
 
117
- def self.scaffold_setup_helper
118
- end
119
-
120
- def self.scaffold_action_setup(root)
121
- if SCAFFOLD_ROOTS.empty?
102
+ module MetaSinatraController
103
+ def scaffold_setup_helper
122
104
  include ScaffoldingExtensions::Controller
123
105
  include ScaffoldingExtensions::SinatraController
124
106
  include ScaffoldingExtensions::Helper
125
107
  include ScaffoldingExtensions::PrototypeHelper
126
108
  include ScaffoldingExtensions::SinatraHelper
127
- end
128
- unless SCAFFOLD_ROOTS.include?(root)
129
- SCAFFOLD_ROOTS << root
130
109
  [:get, :post].each do |req_meth|
131
- Object.send(req_meth, "#{root}/?:meth?/?:request_id?") do
132
- @scaffold_path = root
133
- @scaffold_method = meth = params[:meth] ||= 'index'
134
- params[:id] ||= params[:request_id]
110
+ sreq_meth = req_meth.to_s.upcase
111
+ send(req_meth, %r{\A(?:/(\w+)(?:/(\w+))?)?\z}) do
112
+ captures = params[:captures] || []
113
+ @scaffold_path = request.env['SCRIPT_NAME']
114
+ @scaffold_method = meth = captures[0] || 'index'
115
+ @scaffold_request_method = sreq_meth
116
+ params[:id] ||= captures[1]
135
117
  raise(ArgumentError, 'Method Not Allowed') if req_meth == :get && scaffolded_nonidempotent_method?(meth)
136
118
  raise(Sinatra::NotFound) unless scaffolded_method?(meth)
137
119
  send(meth)
138
120
  end
139
121
  end
122
+ self
140
123
  end
141
- self
142
124
  end
143
125
  end
144
126
 
145
- def scaffold(root, model, options = {})
146
- Sinatra::EventContext.scaffold_action_setup(root).send(:scaffold, model, options)
147
- end
148
-
149
- def scaffold_all_models(root, options = {})
150
- Sinatra::EventContext.scaffold_action_setup(root).send(:scaffold_all_models, options)
151
- end
152
-
153
- def scaffold_habtm(root, model, association)
154
- Sinatra::EventContext.scaffold_action_setup(root).send(:scaffold_habtm, model, association)
127
+ class Sinatra::Base
128
+ extend ScaffoldingExtensions::MetaController
129
+ extend ScaffoldingExtensions::MetaSinatraController
155
130
  end
156
-
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scaffolding_extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Evans
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-12-17 00:00:00 -08:00
12
+ date: 2009-01-29 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15