scaffolding_extensions 1.3.0 → 1.3.1

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/doc/camping.txt CHANGED
@@ -23,3 +23,6 @@ For example:
23
23
  end
24
24
 
25
25
  The path given to scaffold_R will be the root of the plugin.
26
+
27
+ Camping is not fully supported in that you can't override the scaffolded
28
+ layout or scaffold templates without changing the scaffold_template_dir.
data/doc/merb.txt CHANGED
@@ -11,3 +11,8 @@ controllers:
11
11
  scaffold_habtm Model1, :things
12
12
  scaffold_all_models :only=>[Model1, Model2, Model3]
13
13
  end
14
+
15
+ Merb isn't fully supported in that if you override a scaffolded form
16
+ but don't add your own layout, it won't use the scaffolded layout. Also,
17
+ using your own layout and overriding the scaffolded forms is untested,
18
+ though it should work.
@@ -38,7 +38,7 @@ module ScaffoldingExtensions
38
38
  # use the contents of it as the template without the layout.
39
39
  #
40
40
  # There may well be a much better way to do this via modifying the _template_roots, but
41
- # I didn't have much luck and decided to take the path I used with Camping and Sinatra,
41
+ # I didn't have much luck and decided to take the path I used with Camping,
42
42
  # rendering the templates directly.
43
43
  def scaffold_render_template(action, options = {}, render_options = {})
44
44
  suffix = options[:suffix]
@@ -1,13 +1,7 @@
1
- begin
2
- require 'erubis'
3
- ERB = Erubis::Eruby
4
- rescue
5
- require 'erb'
6
- end
1
+ require 'erb'
7
2
  require 'cgi'
8
3
 
9
4
  module ScaffoldingExtensions
10
- SCAFFOLD_ROOTS={}
11
5
  class << self
12
6
  private
13
7
  # Sinatra doesn't have a default location for models, so assume none
@@ -35,22 +29,19 @@ module ScaffoldingExtensions
35
29
  def scaffold_flash
36
30
  {}
37
31
  end
32
+
33
+ # Sinatra's ERB renderer doesn't like "-%>"
34
+ def scaffold_fix_template(text)
35
+ text.gsub('-%>', '%>')
36
+ end
38
37
 
39
- # Proc that redirects to given url
40
38
  def scaffold_redirect_to(url)
41
- env = @sinatra_event.request.env
39
+ env = request.env
42
40
  host = env['HTTP_HOST'] || "#{env['SERVER_NAME']}#{":#{env['SERVER_PORT']}" if env['SERVER_PORT'] && env['SERVER_PORT'].to_i != 80}"
43
- Proc.new{redirect("//#{host}#{url}")}
41
+ redirect("//#{host}#{url}")
44
42
  end
45
43
 
46
- # In order to override the default templates, you need to set
47
- # @scaffold_template_dir and then create a template file inside that
48
- # to override the template (make sure the default templates are also
49
- # in this folder). It doesn't support user modifiable layouts,
50
- # so you'll have to modify the layout.rhtml file in @scaffold_template_dir.
51
- #
52
- # This returns a proc that renders the necessary template using a plain
53
- # text renderer.
44
+ # Render's the scaffolded template. A user can override both the template and the layout.
54
45
  def scaffold_render_template(action, options = {}, render_options = {})
55
46
  suffix = options[:suffix]
56
47
  suffix_action = "#{action}#{suffix}"
@@ -59,15 +50,12 @@ module ScaffoldingExtensions
59
50
  @scaffold_class ||= @scaffold_options[:class]
60
51
  if render_options.include?(:inline)
61
52
  use_js = @scaffold_javascript
62
- text = ERB.new(render_options[:inline]).result(binding)
63
- Proc.new do
64
- headers('Content-Type'=>'text/javascript') if use_js
65
- render(:text, text, :layout=>false)
66
- end
53
+ headers('Content-Type'=>'text/javascript') if use_js
54
+ render(:erb, scaffold_fix_template(render_options[:inline]), :layout=>false)
67
55
  else
68
- @content = ERB.new(File.read(scaffold_path(File.exists?(scaffold_path(suffix_action)) ? suffix_action : action))).result(binding)
69
- text = ERB.new(File.read(scaffold_path('layout'))).result(binding)
70
- Proc.new{render(:text, text, :layout=>false)}
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')
58
+ render(:erb, template, :layout=>layout)
71
59
  end
72
60
  end
73
61
 
@@ -76,11 +64,11 @@ module ScaffoldingExtensions
76
64
  end
77
65
 
78
66
  def scaffold_request_env
79
- @sinatra_event.request.env
67
+ request.env
80
68
  end
81
69
 
82
70
  def scaffold_request_id
83
- @sinatra_event.params[:id]
71
+ params[:id]
84
72
  end
85
73
 
86
74
  def scaffold_request_method
@@ -88,7 +76,7 @@ module ScaffoldingExtensions
88
76
  end
89
77
 
90
78
  def scaffold_request_param(v)
91
- sparams = @sinatra_event.params
79
+ sparams = params
92
80
  unless param = sparams[v.to_sym]
93
81
  param = {}
94
82
  sparams.each do |k,value|
@@ -106,15 +94,9 @@ module ScaffoldingExtensions
106
94
  # is only used for access control, so if you aren't using
107
95
  # scaffold_session_value, it shouldn't matter.
108
96
  def scaffold_session
109
- @sinatra_event.session
97
+ session
110
98
  end
111
99
 
112
- def scaffold_set_vars(meth, event)
113
- @scaffold_path = self.class.scaffold_root
114
- @scaffold_method = meth
115
- @sinatra_event = event
116
- end
117
-
118
100
  # Treats the id option as special, appending it to the path.
119
101
  # Uses the rest of the options as query string parameters.
120
102
  def scaffold_url(action, options = {})
@@ -126,60 +108,49 @@ module ScaffoldingExtensions
126
108
  "#{@scaffold_path}/#{action}#{id}"
127
109
  end
128
110
  end
129
-
130
- # Class methods for Sinatra necessary for Scaffolding Extensions
131
- module MetaSinatraController
132
- include ScaffoldingExtensions::MetaController
133
- attr_accessor :scaffold_root
111
+ end
134
112
 
135
- private
136
- def scaffold_setup_helper
137
- include ScaffoldingExtensions::Controller
138
- include ScaffoldingExtensions::SinatraController
139
- include ScaffoldingExtensions::Helper
140
- include ScaffoldingExtensions::PrototypeHelper
141
- include ScaffoldingExtensions::SinatraHelper
142
- end
113
+ class Sinatra::EventContext
114
+ SCAFFOLD_ROOTS = []
115
+ extend ScaffoldingExtensions::MetaController
116
+
117
+ def self.scaffold_setup_helper
143
118
  end
144
119
 
145
- module TextRenderer
146
- def render_text(template, options = {})
147
- template
120
+ def self.scaffold_action_setup(root)
121
+ if SCAFFOLD_ROOTS.empty?
122
+ include ScaffoldingExtensions::Controller
123
+ include ScaffoldingExtensions::SinatraController
124
+ include ScaffoldingExtensions::Helper
125
+ include ScaffoldingExtensions::PrototypeHelper
126
+ include ScaffoldingExtensions::SinatraHelper
148
127
  end
128
+ unless SCAFFOLD_ROOTS.include?(root)
129
+ SCAFFOLD_ROOTS << root
130
+ [: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]
135
+ raise(ArgumentError, 'Method Not Allowed') if req_meth == :get && scaffolded_nonidempotent_method?(meth)
136
+ raise(Sinatra::NotFound) unless scaffolded_method?(meth)
137
+ send(meth)
138
+ end
139
+ end
140
+ end
141
+ self
149
142
  end
150
143
  end
151
144
 
152
- class Sinatra::EventContext
153
- include ScaffoldingExtensions::TextRenderer
154
- end
155
-
156
145
  def scaffold(root, model, options = {})
157
- scaffold_setup(root).send(:scaffold, model, options)
146
+ Sinatra::EventContext.scaffold_action_setup(root).send(:scaffold, model, options)
158
147
  end
159
148
 
160
149
  def scaffold_all_models(root, options = {})
161
- scaffold_setup(root).send(:scaffold_all_models, options)
150
+ Sinatra::EventContext.scaffold_action_setup(root).send(:scaffold_all_models, options)
162
151
  end
163
152
 
164
153
  def scaffold_habtm(root, model, association)
165
- scaffold_setup(root).send(:scaffold_habtm, model, association)
154
+ Sinatra::EventContext.scaffold_action_setup(root).send(:scaffold_habtm, model, association)
166
155
  end
167
156
 
168
- def scaffold_setup(root)
169
- unless klass = ScaffoldingExtensions::SCAFFOLD_ROOTS[root]
170
- klass = ScaffoldingExtensions::SCAFFOLD_ROOTS[root] = Class.new
171
- klass.send(:extend, ScaffoldingExtensions::MetaSinatraController)
172
- klass.scaffold_root = root
173
- [:get, :post].each do |req_meth|
174
- send(req_meth, "#{klass.scaffold_root}/?:meth?/?:request_id?") do
175
- meth = params[:meth] ||= 'index'
176
- params[:id] ||= params[:request_id]
177
- @controller = klass.new
178
- raise(ArgumentError, 'Method Not Allowed') if req_meth == :get && @controller.send(:scaffolded_nonidempotent_method?, meth)
179
- @controller.send(:scaffold_set_vars, meth, self)
180
- instance_eval(&@controller.send(meth))
181
- end
182
- end
183
- end
184
- klass
185
- end
@@ -471,7 +471,7 @@ module ScaffoldingExtensions::MetaModel
471
471
 
472
472
  # Returns all objects of the associated class not currently associated with this object.
473
473
  def scaffold_unassociated_objects(association, object, options)
474
- scaffold_associated_class(association).scaffold_get_objects(:conditions=>[scaffold_unassociated_condition(association, object), scaffold_session_conditions(options[:session])], :order=>scaffold_select_order_association(association), :include=>scaffold_include_association(association))
474
+ scaffold_associated_class(association).scaffold_get_objects(:conditions=>[scaffold_unassociated_condition(association, object), scaffold_associated_class(association).scaffold_session_conditions(options[:session])], :order=>scaffold_select_order_association(association), :include=>scaffold_include_association(association))
475
475
  end
476
476
 
477
477
  # Updates attributes for the given action, but does not save the record.
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.0
4
+ version: 1.3.1
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-10 00:00:00 -08:00
12
+ date: 2008-12-17 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15