masterview 0.3.1 → 0.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/CHANGELOG +9 -0
- data/RELEASE_NOTES +8 -1
- data/Rakefile +0 -1
- data/TODO +9 -0
- data/doc/configuration.html +18 -0
- data/doc/directives.html +8 -0
- data/examples/rails_app_admin_auth/admin_auth_mixin.rb +47 -0
- data/examples/rails_app_config/masterview/settings.rb +11 -6
- data/lib/masterview/attr_string_parser.rb +6 -4
- data/lib/masterview/directive_registry.rb +3 -2
- data/lib/masterview/directives/.metadata +2 -2
- data/lib/masterview/directives/attr.rb +12 -7
- data/lib/masterview/extras/admin_auth_mixin.rb +49 -0
- data/lib/masterview/extras/app/controllers/masterview_controller.rb +21 -13
- data/lib/masterview/extras/app/views/layouts/masterview_admin.rhtml +4 -2
- data/lib/masterview/extras/app/views/layouts/masterview_admin_config.rhtml +4 -2
- data/lib/masterview/extras/app/views/masterview/admin/create.rhtml +2 -2
- data/lib/masterview/extras/app/views/masterview/admin/interact.rhtml +2 -2
- data/lib/masterview/extras/app/views/masterview/admin/view_rhtml.rhtml +2 -2
- data/lib/masterview/extras/init_mv_admin_pages.rb +52 -0
- data/lib/masterview/initializer.rb +224 -128
- data/lib/masterview/masterview_version.rb +1 -1
- data/lib/masterview/rails_ext/action_view_erb_direct.rb +102 -45
- data/test/fixtures/deprecated_directive_base_directives/submit.rb +17 -0
- data/test/unit/attr_string_parser_test.rb +14 -7
- data/test/unit/directive_insert_generated_comment_test.rb +1 -1
- data/test/unit/directive_link_to_test.rb +12 -0
- data/test/unit/template_test.rb +111 -0
- metadata +11 -6
@@ -34,9 +34,9 @@
|
|
34
34
|
<div class="mv_admin_create content">
|
35
35
|
<h1>Create Empty Shell Template</h1>
|
36
36
|
|
37
|
-
<% if
|
37
|
+
<% if flash[:notice] %>
|
38
38
|
<div class="messages" id="admin_messages">
|
39
|
-
<%= h
|
39
|
+
<%= h flash[:notice] %>
|
40
40
|
</div>
|
41
41
|
<% end %>
|
42
42
|
|
@@ -34,9 +34,9 @@
|
|
34
34
|
<div class="mv_admin_view_rhtml content">
|
35
35
|
<h1>View RHTML - <%= @rhtml_file %></h1>
|
36
36
|
|
37
|
-
<% if
|
37
|
+
<% if flash[:notice] %>
|
38
38
|
<div class="messages" id="admin_messages">
|
39
|
-
<%= h
|
39
|
+
<%= h flash[:notice] %>
|
40
40
|
</div>
|
41
41
|
<% end %>
|
42
42
|
|
@@ -26,6 +26,58 @@ if File.directory?(mv_generator_templates_dir)
|
|
26
26
|
}
|
27
27
|
end
|
28
28
|
|
29
|
+
# load the admin controller's auth checking mixin
|
30
|
+
admin_auth_module = nil
|
31
|
+
admin_auth_mixin_spec = MasterView::ConfigSettings.admin_auth_mixin
|
32
|
+
rails_root_path = MasterView::ConfigSettings.rails_root_path # ::RAILS_ROOT in normalized form
|
33
|
+
app_mv_dir = "#{rails_root_path}/app/masterview" #File.join(rails_root_path, 'app/masterview')
|
34
|
+
if admin_auth_mixin_spec.nil?
|
35
|
+
# convention is to load admin_auth_mixin.rb from app/masterview dir if available
|
36
|
+
module_path = "#{app_mv_dir}/admin_auth_mixin.rb"
|
37
|
+
if File.exist?(module_path)
|
38
|
+
MasterView::Log.debug { 'Using custom app/masterview/admin_auth mixin for MasterView admin controller' }
|
39
|
+
require module_path
|
40
|
+
admin_auth_module = Object.const_get(:MasterViewAdminAuthMixin)
|
41
|
+
else
|
42
|
+
# use built-in authorization mixin
|
43
|
+
MasterView::Log.debug { 'Using default admin_auth mixin for MasterView admin controller (local requests only)' }
|
44
|
+
require 'masterview/extras/admin_auth_mixin'
|
45
|
+
admin_auth_module = MasterView::Admin::AuthMixin
|
46
|
+
end
|
47
|
+
else
|
48
|
+
MasterView::Log.debug { 'Using custom admin_auth mixin for MasterView admin controller' }
|
49
|
+
# load the app's auth_check module
|
50
|
+
file_ref = admin_auth_mixin_spec.fetch(:file, '/admin_auth_mixin')
|
51
|
+
file_loc = admin_auth_mixin_spec[:file_loc]
|
52
|
+
if file_loc.nil?
|
53
|
+
# default is to load auth mixin from the app/masterview dir
|
54
|
+
module_path = "#{app_mv_dir}/#{file_ref}"
|
55
|
+
elsif file_loc == :RAILS_ROOT
|
56
|
+
# relative file reference from RAILS_ROOT
|
57
|
+
module_path = "#{rails_root_path}/#{file_ref}"
|
58
|
+
else
|
59
|
+
# relative file reference to specified location
|
60
|
+
# #?? use file_loc '' if file_ref is full path? or add checks in file_loc.nil? to handle path case??
|
61
|
+
module_path = File.join(file_loc, file_ref)
|
62
|
+
end
|
63
|
+
require module_path
|
64
|
+
# resolve the module reference
|
65
|
+
module_ref = admin_auth_mixin_spec.fetch(:module, :MasterViewAdminAuthMixin)
|
66
|
+
#TODO: handle module namespace ref
|
67
|
+
#if module_ref.is_a?( String)
|
68
|
+
# target = ???err, what's the root of the name space universe?
|
69
|
+
# for name in module_ref.split('::'):
|
70
|
+
# target = target.const_get(name)
|
71
|
+
# end
|
72
|
+
# admin_auth_module = target
|
73
|
+
#else
|
74
|
+
# admin_auth_module = const_get(module_ref)
|
75
|
+
#end
|
76
|
+
admin_auth_module = Object.const_get(module_ref)
|
77
|
+
end
|
78
|
+
#assert admin_auth_module.method_defined?(:allow_access?)
|
79
|
+
MasterView.const_set('MasterViewAdminAuthMixin', admin_auth_module)
|
80
|
+
|
29
81
|
# add our app directories with the masterview_controller to the load path
|
30
82
|
mv_controller_code_dirs = Dir[File.join(MasterView::ConfigSettings.mv_code_base_dir, '/extras/app/controllers')].select { |dir| File.directory?(dir) }
|
31
83
|
|
@@ -22,18 +22,18 @@
|
|
22
22
|
#++
|
23
23
|
#
|
24
24
|
# == MasterView Configuration and Initialization
|
25
|
-
#
|
25
|
+
#
|
26
26
|
# The MasterView template engine supports a number of configuration settings
|
27
27
|
# which allow a client to easily customize its operation.
|
28
28
|
#
|
29
|
-
# A MasterView::Configuration specification is used to allow the application to
|
29
|
+
# A MasterView::Configuration specification is used to allow the application to
|
30
30
|
# specify custom configuration options during application startup. The configuration options
|
31
31
|
# are installed in MasterView when its Initializer is run, which handles
|
32
32
|
# loading and configuring MasterView for operation.
|
33
|
-
#
|
33
|
+
#
|
34
34
|
#--
|
35
|
-
# This style of configuration specification + initializer follows the technique
|
36
|
-
# used by Rails itself. A configuration specification can be customized by the
|
35
|
+
# This style of configuration specification + initializer follows the technique
|
36
|
+
# used by Rails itself. A configuration specification can be customized by the
|
37
37
|
# application in its startup and is used by the Initialzer to configure
|
38
38
|
# the MasterView template engine implementation at load time.
|
39
39
|
# [D. Lewis 31-May-2006]
|
@@ -56,23 +56,23 @@ DEBUG_DIRECTIVE_PATH = false #:nodoc: # temp debug
|
|
56
56
|
|
57
57
|
module MasterView
|
58
58
|
|
59
|
-
# A Configuration holds all the configuration settings used the
|
59
|
+
# A Configuration holds all the configuration settings used the
|
60
60
|
# MasterView::Initializer to configure the template engine.
|
61
|
-
#
|
62
|
-
# Configuration provides defaults that suit most Rails applications.
|
63
|
-
# You can change the default settings in the configuration to customize
|
61
|
+
#
|
62
|
+
# Configuration provides defaults that suit most Rails applications.
|
63
|
+
# You can change the default settings in the configuration to customize
|
64
64
|
# MasterView with options suitable for your application.
|
65
|
-
#
|
66
|
-
# In the most common usage pattern, a Configuration instance initialized
|
67
|
-
# with the standard default settings is created implicitly when the
|
65
|
+
#
|
66
|
+
# In the most common usage pattern, a Configuration instance initialized
|
67
|
+
# with the standard default settings is created implicitly when the
|
68
68
|
# Initializer is run, which happens automatically
|
69
69
|
# when Masterview is installed as a plugin in a Rails application.
|
70
70
|
# Application-specific settings are then loaded from the application's
|
71
71
|
# +config+ directory and used by the Initializer to configure
|
72
72
|
# the MasterView template engine for operation.
|
73
|
-
#
|
73
|
+
#
|
74
74
|
# When using MasterView in a standalone application (i.e., not within rails),
|
75
|
-
# it is also possible to create the Configuration instance in advance and
|
75
|
+
# it is also possible to create the Configuration instance in advance and
|
76
76
|
# pass it in explicitly to the Initializer. This technique can be useful
|
77
77
|
# when it is necessary to establish the application root directory location
|
78
78
|
# that MasterView uses during its operation or to specify to location of the
|
@@ -122,51 +122,51 @@ module MasterView
|
|
122
122
|
|
123
123
|
# Path to the root location for the application.
|
124
124
|
# Used for resolving relative references.
|
125
|
-
#
|
125
|
+
#
|
126
126
|
# For a rails application, this is +RAILS_ROOT+.
|
127
|
-
#
|
127
|
+
#
|
128
128
|
attr_accessor :root_path
|
129
129
|
|
130
|
-
# Path to the directory containing the application's MasterView
|
130
|
+
# Path to the directory containing the application's MasterView
|
131
131
|
# configuration settings files (if any). If no configuration
|
132
132
|
# directory or settings files are defined, MasterView runs
|
133
133
|
# with the standard default configuration options.
|
134
|
-
#
|
134
|
+
#
|
135
135
|
# Specified as a relative path from the application's +root_path+.
|
136
|
-
#
|
136
|
+
#
|
137
137
|
# Default: for a Rails application, this is <tt>RAILS_ROOT/config/masterview</tt>.
|
138
|
-
#
|
138
|
+
#
|
139
139
|
attr_accessor :config_dir_path
|
140
|
-
# Specify the directory where masterview templates are located
|
140
|
+
# Specify the directory where masterview templates are located
|
141
141
|
# as a relative path from the application's +root_path+.
|
142
142
|
def config_dir_path= rel_path #:nodoc:
|
143
143
|
# bolts down abs path, thanks to our firm roots
|
144
144
|
@config_dir_path = rel_path.nil? ? nil : ( rel_path.empty? ? root_path : File.join( root_path, rel_path ))
|
145
145
|
end
|
146
146
|
|
147
|
-
# The current execution environment, if applicable
|
147
|
+
# The current execution environment, if applicable
|
148
148
|
# (e.g., 'development', 'test', 'production').
|
149
|
-
#
|
149
|
+
#
|
150
150
|
# Used for loading application settings from config directory, if available.
|
151
|
-
#
|
151
|
+
#
|
152
152
|
# For a Rails application, this is +RAILS_ENV+.
|
153
|
-
#
|
153
|
+
#
|
154
154
|
attr_accessor :environment
|
155
155
|
|
156
156
|
# Paths of directories to load directives from.
|
157
|
-
#
|
158
|
-
# The directory containing the built-in MasterView directives
|
157
|
+
#
|
158
|
+
# The directory containing the built-in MasterView directives
|
159
159
|
# is installed by default. If the application provides
|
160
160
|
# a <tt>masterview/directives</tt> directory in its +root_path+,
|
161
161
|
# that directory is also automatically added to the directives
|
162
162
|
# load path.
|
163
|
-
#
|
163
|
+
#
|
164
164
|
# A directive load path entry specifiess a directory path
|
165
165
|
# from which masterview directives are loaded.
|
166
166
|
# Configuration options can optionally be specified to override
|
167
167
|
# or extend any .metadata specifications in the directory.
|
168
168
|
#
|
169
|
-
# Use add_directive_path to append additional directory path(s)
|
169
|
+
# Use add_directive_path to append additional directory path(s)
|
170
170
|
# from which to load custom directives.
|
171
171
|
#
|
172
172
|
attr_accessor :directive_load_path
|
@@ -187,9 +187,9 @@ module MasterView
|
|
187
187
|
#
|
188
188
|
# Optionally specify options for the directives loaded
|
189
189
|
# from this directory:
|
190
|
-
#
|
190
|
+
#
|
191
191
|
# :default - metadata defaults
|
192
|
-
#
|
192
|
+
#
|
193
193
|
# Metadata defaults extend or override any defaults specified
|
194
194
|
# in the dir_path/.metadata file, if defined, allowing application
|
195
195
|
# customization of the default defaults.
|
@@ -197,46 +197,46 @@ module MasterView
|
|
197
197
|
def add_directive_path(dir_path, options=nil)
|
198
198
|
directive_load_path << DirectiveLoadPath::PathEntry.new( dir_path, options )
|
199
199
|
end
|
200
|
-
|
201
|
-
# Relative path from +root_path+ of the temp directory used for creating
|
200
|
+
|
201
|
+
# Relative path from +root_path+ of the temp directory used for creating
|
202
202
|
# backup files before rebuilding/updating a template file.
|
203
|
-
#
|
203
|
+
#
|
204
204
|
# Set to nil to suppress backups.
|
205
|
-
#
|
205
|
+
#
|
206
206
|
# Default: <tt>RAILS_ROOT/tmp/masterview/rebuild/backups</tt>
|
207
207
|
#--
|
208
208
|
# ISSUE: change this to use IOMgr mapping, how best to do this config??
|
209
209
|
# Leave existing mechanism here, but drop out of documentation and examples
|
210
210
|
# until resolved
|
211
211
|
#++
|
212
|
-
attr_accessor :rebuild_backups_tmp_dir_path #:nodoc:
|
212
|
+
attr_accessor :rebuild_backups_tmp_dir_path #:nodoc:
|
213
213
|
|
214
214
|
# Logger which will be used to record debug, warning, and error messages.
|
215
|
-
#
|
215
|
+
#
|
216
216
|
# Supported loggers:
|
217
217
|
# 'log4r' - the Log4r logging library
|
218
218
|
# 'logger' - Logger in the ruby standard class library
|
219
|
-
#
|
219
|
+
#
|
220
220
|
# Default: uses <code>Log4r</code> if available, otherwise a standard ruby +Logger+.
|
221
221
|
attr_accessor :logger
|
222
222
|
|
223
223
|
# Logging severity threshold for the logger.
|
224
|
-
#
|
224
|
+
#
|
225
225
|
# Specify the name of the logging level to use with the configured logger.
|
226
226
|
# Standard logging levels in both Log4r and ruby Logger are
|
227
227
|
# +DEBUG+, +INFO+, +WARN+, +ERROR+, +FATAL+.
|
228
228
|
# Other level names depend on the configured logger.
|
229
|
-
#
|
229
|
+
#
|
230
230
|
# Default: +INFO+ for development, +WARN+ otherwise
|
231
231
|
attr_accessor :log_level
|
232
232
|
|
233
233
|
# Sets a block which will be executed after MasterView has been fully initialized.
|
234
|
-
# Useful for per-environment configuration which depends on the plugin being
|
234
|
+
# Useful for per-environment configuration which depends on the plugin being
|
235
235
|
# fully initialized.
|
236
236
|
def after_initialize(&after_initialize_block)
|
237
237
|
@after_initialize_block = after_initialize_block
|
238
238
|
end
|
239
|
-
|
239
|
+
|
240
240
|
# Returns the block set in Configuration#after_initialize
|
241
241
|
def after_initialize_block
|
242
242
|
@after_initialize_block
|
@@ -245,14 +245,14 @@ module MasterView
|
|
245
245
|
# === Template Source Options
|
246
246
|
|
247
247
|
# Path to the directory where masterview templates are located.
|
248
|
-
#
|
248
|
+
#
|
249
249
|
# Assign the value as a relative path from the application's +root_path+
|
250
250
|
# or use the +template_src_dir_abs_path+ method to specify an absolute path.
|
251
|
-
#
|
251
|
+
#
|
252
252
|
# Default: <tt>RAILS_ROOT/app/views</tt> for a rails application
|
253
253
|
# or <tt>{root_path}/masterview/templates</tt> for a non-rails application.
|
254
254
|
attr_accessor :template_src_dir_path
|
255
|
-
# Specify the directory where masterview templates are located
|
255
|
+
# Specify the directory where masterview templates are located
|
256
256
|
# as a relative path from the application's +root_path+.
|
257
257
|
def template_src_dir_path= rel_path #:nodoc:
|
258
258
|
# bolts down abs path, thanks to our firm roots
|
@@ -265,7 +265,7 @@ module MasterView
|
|
265
265
|
|
266
266
|
# Filename pattern for masterview template files
|
267
267
|
# within the template source directory.
|
268
|
-
#
|
268
|
+
#
|
269
269
|
# Default: <tt>'*.html'</tt>
|
270
270
|
attr_accessor :template_filename_pattern
|
271
271
|
|
@@ -274,33 +274,33 @@ module MasterView
|
|
274
274
|
# design-time assert references for images, stylesheets,
|
275
275
|
# and javascript files into relative references for use
|
276
276
|
# with the standard Rails asset helper functions.
|
277
|
-
#
|
277
|
+
#
|
278
278
|
# The patterns are a hash indexed by asset type.
|
279
279
|
# Asset types are :images, :stylesheets, :javascripts
|
280
|
-
#
|
281
|
-
# The standard patterns match path prefixes up through
|
280
|
+
#
|
281
|
+
# The standard patterns match path prefixes up through
|
282
282
|
# <code>public/<i>asset-type</i></code>. For example,
|
283
283
|
# an <code>mv:stylesheet_link</code> directive of the form:
|
284
|
-
#
|
284
|
+
#
|
285
285
|
# <link rel="stylesheet" type="text/css" href="../../../public/stylesheets/mystyles.css" mv:stylesheet_link="" />
|
286
|
-
#
|
286
|
+
#
|
287
287
|
# would match the standard base-dir prefix and result in:
|
288
|
-
#
|
288
|
+
#
|
289
289
|
# <%= stylesheet_link_tag "mystyles" %>
|
290
|
-
#
|
290
|
+
#
|
291
291
|
attr_accessor :template_asset_base_ref_pattern
|
292
292
|
|
293
293
|
# === Template Generation Options
|
294
294
|
|
295
295
|
# Path to the directory where Masterview template output (rhtml)
|
296
296
|
# will be generated.
|
297
|
-
#
|
297
|
+
#
|
298
298
|
# Assign the value as a relative path from the application's +root_path+
|
299
299
|
# or use the +template_dst_dir_abs_path+ method to specify an absolute path.
|
300
|
-
#
|
300
|
+
#
|
301
301
|
# Default: <tt>RAILS_ROOT/app/views</tt>
|
302
302
|
attr_accessor :template_dst_dir_path
|
303
|
-
# Specify the directory where masterview template output is generated
|
303
|
+
# Specify the directory where masterview template output is generated
|
304
304
|
# as a relative path from the application's +root_path+.
|
305
305
|
def template_dst_dir_path= rel_path #:nodoc:
|
306
306
|
# bolts down abs path, thanks to our firm roots
|
@@ -311,55 +311,55 @@ module MasterView
|
|
311
311
|
@template_dst_dir_path = abs_path
|
312
312
|
end
|
313
313
|
|
314
|
-
# Filename extension to use for generated output files if not
|
314
|
+
# Filename extension to use for generated output files if not
|
315
315
|
# explicitly specified in the +mv:generate+ attribute value.
|
316
|
-
#
|
316
|
+
#
|
317
317
|
# Default: <tt>'.rhtml'</tt>
|
318
318
|
attr_accessor :output_filename_extension
|
319
319
|
|
320
320
|
# Filename extension to use for generated files if not explicitly specified.
|
321
|
-
#
|
321
|
+
#
|
322
322
|
# Default: <tt>'.rhtml'</tt>
|
323
323
|
attr_accessor :generated_file_default_extension #FIXME
|
324
324
|
|
325
325
|
# Boolean which controls whether to include a comment in template
|
326
326
|
# output files indicating that the file was generated by MasterView.
|
327
|
-
#
|
327
|
+
#
|
328
328
|
# By default, a warning comment is generated in template output files
|
329
329
|
# indicating that the file was generated by MasterView from a template
|
330
330
|
# and should not be directly edited, as any changes would be lost when the
|
331
331
|
# output file is regenerated.
|
332
|
-
#
|
332
|
+
#
|
333
333
|
# Default: +true+
|
334
334
|
attr_accessor :include_generated_file_comment
|
335
335
|
|
336
|
-
# Text for generated-file comment inserted in rhtml template output files
|
336
|
+
# Text for generated-file comment inserted in rhtml template output files
|
337
337
|
# generated by MasterView.
|
338
|
-
#
|
338
|
+
#
|
339
339
|
# Standard comment includes the name of the master template file which contains
|
340
340
|
# the source to edit.
|
341
|
-
#
|
341
|
+
#
|
342
342
|
# Variable substitution on the comment text will replace a reference
|
343
343
|
# to <tt>{template_path}</tt> with the pathname of the source template file.
|
344
|
-
#
|
344
|
+
#
|
345
345
|
attr_accessor :generated_file_comment
|
346
346
|
|
347
347
|
# === Template Parsing Options
|
348
348
|
|
349
|
-
# Specify whether MasterView should handle exceptions when
|
349
|
+
# Specify whether MasterView should handle exceptions when
|
350
350
|
# parsing template files.
|
351
|
-
#
|
352
|
-
# Exceptions that occur during template parsing are always
|
351
|
+
#
|
352
|
+
# Exceptions that occur during template parsing are always
|
353
353
|
# recorded in the debug log. These are generally problems
|
354
354
|
# caused by invalid (x)html in the template.
|
355
|
-
#
|
355
|
+
#
|
356
356
|
# Set to +true+ to have the template parser catch exceptions and
|
357
357
|
# continue processing after logging a problem report.
|
358
|
-
#
|
358
|
+
#
|
359
359
|
# Set to +false+ to have exceptions raised to the application.
|
360
|
-
#
|
360
|
+
#
|
361
361
|
# Default: +true+
|
362
|
-
#
|
362
|
+
#
|
363
363
|
attr_accessor :handle_parse_exceptions
|
364
364
|
|
365
365
|
# Default option settings for template parsing (a hash)
|
@@ -375,25 +375,25 @@ module MasterView
|
|
375
375
|
|
376
376
|
# XML name space prefix for builtin MasterView directive attributes in template html.
|
377
377
|
# e.g. mv:generate="target.rhtml".
|
378
|
-
#
|
378
|
+
#
|
379
379
|
# Default: <tt>'mv:'</tt>
|
380
380
|
attr_accessor :namespace_prefix
|
381
381
|
|
382
382
|
# XML name space prefix for MasterView extension directive attributes in template html.
|
383
383
|
# e.g. mvx:custom_directive="foo".
|
384
|
-
#
|
384
|
+
#
|
385
385
|
# Default: <tt>'mvx:'</tt>
|
386
386
|
attr_accessor :namespace_prefix_extensions
|
387
387
|
|
388
388
|
# Xhtml-safe substitution for '<%' in a masterview template
|
389
389
|
# NOTE: you must also update inline_erb_substitution_regex if this is changed.
|
390
|
-
#
|
390
|
+
#
|
391
391
|
# Default: <tt>'{{{'</tt>
|
392
392
|
attr_accessor :inline_erb_start
|
393
393
|
|
394
394
|
# Xhtml safe substitution for '%>'in a masterview template
|
395
395
|
# NOTE: you must also update inline_erb_substitution_regex if this is changed.
|
396
|
-
#
|
396
|
+
#
|
397
397
|
# Default: <tt>'}}}'</tt>
|
398
398
|
attr_accessor :inline_erb_end
|
399
399
|
|
@@ -403,67 +403,99 @@ module MasterView
|
|
403
403
|
|
404
404
|
# === Rails Application Options
|
405
405
|
|
406
|
-
# Boolean which specifies whether masterview templates are parsed
|
406
|
+
# Boolean which specifies whether masterview templates are parsed
|
407
407
|
# during initial application startup loading.
|
408
|
-
#
|
408
|
+
#
|
409
409
|
# Set to +false+ to disable all load-time parsing.
|
410
410
|
# Template parsing must be manually triggered when the auto-parse option is disabled.
|
411
|
-
#
|
411
|
+
#
|
412
412
|
# Default: +true+
|
413
413
|
attr_accessor :parse_masterview_templates_at_startup
|
414
414
|
|
415
415
|
# Boolean which determines whether masterview templates are automatically
|
416
416
|
# reparsed if the template changes after initial application loading.
|
417
|
-
#
|
417
|
+
#
|
418
418
|
# Set to +true+ to monitor masterview templates for file system changes
|
419
419
|
# during Rails request dispatching.
|
420
|
-
#
|
420
|
+
#
|
421
421
|
# Set to +false+ to disable changed-template monitoring.
|
422
422
|
# Template parsing must be manually triggered when the auto-parse option is disabled.
|
423
|
-
#
|
423
|
+
#
|
424
424
|
# This option is only supported when running as part of a Rails application.
|
425
425
|
# It is enabled by default in the standard Rails development configuration
|
426
426
|
# (+parse_masterview_templates_at_startup+ is enabled and
|
427
|
-
# ActionController::Base.perform_caching is false so that changed classes
|
427
|
+
# ActionController::Base.perform_caching is false so that changed classes
|
428
428
|
# are dynamically reloaded during request dispatching).
|
429
|
-
#
|
429
|
+
#
|
430
430
|
# Automatic change-detection and reparsing of masterview templates is disabled
|
431
431
|
# by default in the usual Rails configuration for production mode
|
432
432
|
# (ActionController::Base.perform_caching is on to enable loaded class caching).
|
433
|
-
#
|
434
|
-
# Default: +true+ if parse_masterview_templates_at_startup is enabled
|
433
|
+
#
|
434
|
+
# Default: +true+ if parse_masterview_templates_at_startup is enabled
|
435
435
|
# and ActionController is reloading changed classes (no caching)
|
436
436
|
attr_accessor :reparse_changed_masterview_templates
|
437
437
|
|
438
|
+
# Authorization module which will be mixed into MasterView Admin controller
|
439
|
+
# to determine whether access should be granted to a user.
|
440
|
+
#
|
441
|
+
# The module must implement the method allow_access? which returns a boolean
|
442
|
+
# indicating whether access is allowed to the MasterView administration pages.
|
443
|
+
# By default, the module name for a custom mixin is MasterViewAdminAuthMixin.
|
444
|
+
#
|
445
|
+
# The admin_auth_check mixin is included in an ApplicationController subclass
|
446
|
+
# and thus may use any services available to controllers in your application.
|
447
|
+
#
|
448
|
+
# Defaults to local machine access only using local_request? check.
|
449
|
+
# Automatically installs custom mixin from app/masterview/admin_auth_mixin.rb
|
450
|
+
# if available.
|
451
|
+
#
|
452
|
+
# To load a different file from app/masterview or use a different module name:
|
453
|
+
#
|
454
|
+
# config.admin_auth_mixin = {
|
455
|
+
# :file => 'alt_admin_auth_mixin', # module file in #{RAILS_ROOT}/app/masterview dir
|
456
|
+
# :module => :AltMasterViewAdminAuthMixin, # default is :MasterViewAdminAuthMixin
|
457
|
+
# }
|
458
|
+
#
|
459
|
+
# To load a mixin from the rails app's lib directory:
|
460
|
+
#
|
461
|
+
# config.admin_auth_mixin = {
|
462
|
+
# :file => 'lib/custom/mv_admin_auth_mixin', # module file in rails lib dir
|
463
|
+
# :file_loc => :RAILS_ROOT, # default location for rel refs is #{RAILS_ROOT}/app/masterview
|
464
|
+
# :module => :CustomMasterViewAdminAuthMixin, # default is :MasterViewAdminAuthMixin
|
465
|
+
# }
|
466
|
+
#
|
467
|
+
# see examples/rails_app_admin_auth/admin_auth_mixin.rb for more details
|
468
|
+
attr_accessor :admin_auth_mixin
|
469
|
+
|
438
470
|
# Enable MasterView admin pages in the rails application.
|
439
|
-
#
|
471
|
+
#
|
440
472
|
# Enables the masterview admin controller at <tt>http://yourappdomain/masterview</tt>.
|
441
|
-
#
|
473
|
+
#
|
442
474
|
# Default: +false+
|
443
475
|
attr_accessor :enable_admin_pages
|
444
476
|
|
445
477
|
# Enable MasterView admin view rhtml feature
|
446
|
-
#
|
447
|
-
# If MasterView admin pages are enabled, then you may set this feature to true and it
|
478
|
+
#
|
479
|
+
# If MasterView admin pages are enabled, then you may set this feature to true and it
|
448
480
|
# will allow you to get to the generated rhtml from the MasterView admin page which is
|
449
481
|
# especially useful for debugging or understanding how MasterView is interpretting the
|
450
|
-
# your templates. When enabled you may click on any of the generated rhtml parts from
|
482
|
+
# your templates. When enabled you may click on any of the generated rhtml parts from
|
451
483
|
# the list view and it will show you the rhtml that is generated. For security purposes
|
452
|
-
# you will probably want this to disable this feature in production (or even better
|
484
|
+
# you will probably want this to disable this feature in production (or even better
|
453
485
|
# disable admin pages itself). Alternatively there is a rake task called mv:view_rhtml
|
454
486
|
# which allows you to see the rhtml from the command line (regardless of this setting).
|
455
487
|
#
|
456
488
|
# Default +false+
|
457
489
|
attr_accessor :enable_view_rhtml
|
458
490
|
|
459
|
-
# Generate rhtml files if true, rails will load them from there. Otherwise when this
|
460
|
-
# setting is false, enable rails app to read rhtml(erb) directly from MasterView cache
|
491
|
+
# Generate rhtml files if true, rails will load them from there. Otherwise when this
|
492
|
+
# setting is false, enable rails app to read rhtml(erb) directly from MasterView cache
|
461
493
|
# bypassing the serialization to the file system.
|
462
494
|
# Default: +false+
|
463
495
|
attr_accessor :generate_rhtml_files
|
464
496
|
|
465
497
|
# These are the original default parser options, whatever is set in the config
|
466
|
-
# will be merged with these to arrive at the result. This allows us to easily
|
498
|
+
# will be merged with these to arrive at the result. This allows us to easily
|
467
499
|
# add new defaults in and even if users empty this hash, the defaults will get added
|
468
500
|
# to disable they specifically set something to false or nil
|
469
501
|
OriginalDefaultParserOptions = { :tidy => false, :escape_erb => true, :default_generate => true } # :nodoc: save the originals
|
@@ -474,20 +506,20 @@ module MasterView
|
|
474
506
|
|
475
507
|
# Create a new Configuration instance, initialized with the default
|
476
508
|
# values.
|
477
|
-
#
|
509
|
+
#
|
478
510
|
# Optional arguments to the constructor allow for initializing defaults
|
479
511
|
# for a rails app when not actually running rails or for initializing
|
480
512
|
# defaults for a standalone app with context anchored at some well-defined
|
481
513
|
# point in space (other than where we're actually running).
|
482
|
-
#
|
514
|
+
#
|
483
515
|
# :app_root_path => path to the root directory of the application
|
484
516
|
# :rails_app_root_path => path to the root directory of a Rails app
|
485
517
|
# :environment => current environment for loading settings
|
486
|
-
#
|
518
|
+
#
|
487
519
|
# The +app_root_path+ and +rails_app_root_path+ arguments are mutually exclusive.
|
488
520
|
# Use +rails_app_root_path+ when operating on a Rails application which
|
489
521
|
# isn't actually running; use +app_root_path+ for a non-rails application.
|
490
|
-
#
|
522
|
+
#
|
491
523
|
def initialize( params={} ) #:nodoc:
|
492
524
|
|
493
525
|
rails_env = (defined?(RAILS_ENV)) ? RAILS_ENV : nil
|
@@ -565,7 +597,7 @@ module MasterView
|
|
565
597
|
self.root_path = program_root_path
|
566
598
|
end
|
567
599
|
# For a rails app, we have a point of view on where to find config files.
|
568
|
-
# A standalone client needs to proactively tell us where to find their settings.
|
600
|
+
# A standalone client needs to proactively tell us where to find their settings.
|
569
601
|
self.config_dir_path = rails_app? ? "config/masterview" : nil
|
570
602
|
self.environment = on_rails? ? ::RAILS_ENV : env
|
571
603
|
self.directive_load_path = DirectiveLoadPath::Path.new
|
@@ -573,7 +605,7 @@ module MasterView
|
|
573
605
|
discover_standard_directive_path_additions()
|
574
606
|
|
575
607
|
#TODO: if rails_app? && File.exist?( "#{rails_root_path}/app/masterview/directives" ) THEN append it as well
|
576
|
-
self.rebuild_backups_tmp_dir_path = rails_app? ? File.join( rails_root_path, 'tmp/masterview/rebuild/backups') : nil
|
608
|
+
self.rebuild_backups_tmp_dir_path = rails_app? ? File.join( rails_root_path, 'tmp/masterview/rebuild/backups') : nil
|
577
609
|
# use Log4r by default if available, otherwise Logger from standard ruby library
|
578
610
|
# find out if Kernel#require will succeed if we try to load Log4R
|
579
611
|
log4r_dir = $:.detect { |dir| File.exists?("#{dir}/log4r.rb") } #? path_contains? predicate somewhere??
|
@@ -605,10 +637,10 @@ module MasterView
|
|
605
637
|
self.generated_file_default_extension = '.rhtml'
|
606
638
|
self.include_generated_file_comment = true
|
607
639
|
self.generated_file_comment = <<-END
|
608
|
-
# WARNING - This is a generated file created by MasterView.
|
640
|
+
# WARNING - This is a generated file created by MasterView.
|
609
641
|
# Do not edit - changes will be lost when this file is re-generated.
|
610
|
-
#
|
611
|
-
# To make changes, edit the MasterView source file located at:
|
642
|
+
#
|
643
|
+
# To make changes, edit the MasterView source file located at:
|
612
644
|
END
|
613
645
|
self.generated_file_comment << '# #{template_path}' # carefully avoid premature subst eval
|
614
646
|
|
@@ -628,10 +660,11 @@ module MasterView
|
|
628
660
|
# Rails application options
|
629
661
|
self.parse_masterview_templates_at_startup = true
|
630
662
|
self.reparse_changed_masterview_templates = on_rails? ? (not ActionController::Base.perform_caching) : false
|
663
|
+
self.admin_auth_mixin = nil # if defined then this module will be included in MasterView controller
|
631
664
|
self.enable_admin_pages = is_development
|
632
665
|
self.enable_view_rhtml = is_development
|
633
666
|
self.generate_rhtml_files = false
|
634
|
-
|
667
|
+
|
635
668
|
STDOUT.puts "...mv config initialized with default settings\n" if debug_TRACE_HACK
|
636
669
|
|
637
670
|
self.initialization_messages = [] # for installer validation checking and problem reporting
|
@@ -648,7 +681,7 @@ module MasterView
|
|
648
681
|
|
649
682
|
# see if this app has the std file structure that indicates a rails application
|
650
683
|
def looks_like_rails_app? #:nodoc:
|
651
|
-
std_rails_directories = [ 'app', 'config', 'public' ]
|
684
|
+
std_rails_directories = [ 'app', 'config', 'public' ]
|
652
685
|
std_rails_directories.each { | dir_path |
|
653
686
|
return if ! File.directory?(dir_path)
|
654
687
|
}
|
@@ -672,16 +705,79 @@ module MasterView
|
|
672
705
|
config_dir_path ? "#{config_dir_path}/settings.rb" : nil
|
673
706
|
end
|
674
707
|
|
675
|
-
# The path to the current environment's settings file (development.rb, etc.).
|
708
|
+
# The path to the current environment's settings file (development.rb, etc.).
|
676
709
|
# By default the file is at <tt>config/masterview/environments/{environment}.rb</tt>.
|
677
710
|
def environment_settings_path
|
678
711
|
(config_dir_path && environment) ? "#{config_dir_path}/environments/#{environment}.rb" : nil
|
679
712
|
end
|
680
713
|
|
714
|
+
# Add masterview directive implementations from plugins
|
715
|
+
# to the masterview directive load path
|
716
|
+
#
|
717
|
+
# EXPERIMENTAL PROTOTYPE - NOT YET PUBLICIZED [DJL 13-Feb-2007]
|
718
|
+
def add_plugin_directives(*base_paths) #:nodo:
|
719
|
+
# append plugin directives in alphabetical order, per Rails plugin loading
|
720
|
+
plugin_directives = find_plugin_directives(base_paths)
|
721
|
+
plugin_directives.each { | plugin_dir_path |
|
722
|
+
add_directive_path plugin_dir_path
|
723
|
+
}
|
724
|
+
plugin_directives
|
725
|
+
end
|
726
|
+
|
727
|
+
protected
|
728
|
+
# Return list of directives paths from plugins
|
729
|
+
def find_plugin_directives(*base_paths)
|
730
|
+
directive_paths = []
|
731
|
+
find_plugins(base_paths).each do | plugin_dir_path |
|
732
|
+
next if File.basename(plugin_dir_path) == 'masterview' #skip masterview's own built-in directives
|
733
|
+
directive_dir_path = File.join(plugin_dir_path, 'directives')
|
734
|
+
if File.directory?(directive_dir_path)
|
735
|
+
directive_paths << directive_dir_path
|
736
|
+
else
|
737
|
+
directive_dir_path = File.join(plugin_dir_path, 'lib', 'directives')
|
738
|
+
if File.directory?(directive_dir_path)
|
739
|
+
directive_paths << directive_dir_path
|
740
|
+
end
|
741
|
+
end
|
742
|
+
end
|
743
|
+
directive_paths
|
744
|
+
end
|
745
|
+
|
746
|
+
# cloned from Rails::Initializer {1.1.2); updated for Rails 1.2.2
|
747
|
+
# Return a list of plugin paths within base_path. A plugin path is
|
748
|
+
# a directory that contains either a lib directory or an init.rb file.
|
749
|
+
# This recurses into directories which are not plugin paths, so you
|
750
|
+
# may organize your plugins within the plugin path.
|
751
|
+
def find_plugins(*base_paths) #:nodoc:
|
752
|
+
base_paths.flatten.inject([]) do |plugins, base_path|
|
753
|
+
Dir.glob(File.join(base_path, '*')).each do |path|
|
754
|
+
if plugin_path?(path)
|
755
|
+
plugins << path if plugin_enabled?(path) #enabled check per Rails 1.2
|
756
|
+
elsif File.directory?(path)
|
757
|
+
plugins += find_plugins(path)
|
758
|
+
end
|
759
|
+
end
|
760
|
+
plugins
|
761
|
+
end
|
762
|
+
end
|
763
|
+
|
764
|
+
# cloned from Rails::Initializer {1.1.2)
|
765
|
+
def plugin_path?(path) #:nodoc:
|
766
|
+
File.directory?(path) and (File.directory?(File.join(path, 'lib')) or File.file?(File.join(path, 'init.rb')))
|
767
|
+
end
|
768
|
+
|
769
|
+
# cloned from Rails::Initializer {1.2.2)
|
770
|
+
def plugin_enabled?(path) #:nodoc:
|
771
|
+
#ISSUE: how can our plugin init get at the rails config which is loading it?
|
772
|
+
#... don't want to duplicate notion of enabled plugins
|
773
|
+
###TODO: (rails) configuration.plugins.nil? || configuration.plugins.include?(File.basename(path))
|
774
|
+
true
|
775
|
+
end
|
776
|
+
|
681
777
|
end
|
682
778
|
|
683
779
|
# The Initializer is responsible for processing the MasterView configuration.
|
684
|
-
#
|
780
|
+
#
|
685
781
|
# In a Rails application using the MasterView facilities,
|
686
782
|
# the Initializer is run automatically during rails startup
|
687
783
|
# when the plugin is loaded. No special action is required
|
@@ -693,20 +789,20 @@ module MasterView
|
|
693
789
|
# environment-specific values in <tt>config/masterview/environments/{environment}.rb</tt>.
|
694
790
|
# The settings files are executed with the +config+ variable initialized to
|
695
791
|
# the current configuration. This is the standard technique for a Rails application.
|
696
|
-
#
|
697
|
-
# An application using the MasterView facilities outside the Rails context
|
792
|
+
#
|
793
|
+
# An application using the MasterView facilities outside the Rails context
|
698
794
|
# must run the MasterView::Initializer during its application startup.
|
699
|
-
#
|
795
|
+
#
|
700
796
|
# It can be run as a simple command that uses the default configuration:
|
701
797
|
#
|
702
798
|
# require 'masterview/initializer'
|
703
799
|
# MasterView::Initializer.run
|
704
800
|
#
|
705
801
|
# or more simply just load MasterView:
|
706
|
-
#
|
802
|
+
#
|
707
803
|
# require 'masterview'
|
708
804
|
#
|
709
|
-
# In order to customize the MasterView configuration outside the Rails context,
|
805
|
+
# In order to customize the MasterView configuration outside the Rails context,
|
710
806
|
# you must explicitly provide a basic Configuration to the Initializer
|
711
807
|
# which specifies the root location of the application and the paths
|
712
808
|
# to the template directories if the default locations are not appropriate.
|
@@ -733,7 +829,7 @@ module MasterView
|
|
733
829
|
# MasterView::Initializer.run(:initialize_configuration)
|
734
830
|
#
|
735
831
|
# This is useful if you only want the config settings initialized, without
|
736
|
-
# incurring the overhead of completely loading the entire component.
|
832
|
+
# incurring the overhead of completely loading the entire component.
|
737
833
|
#
|
738
834
|
def self.run(command = :process, configuration = Configuration.new)
|
739
835
|
if block_given?
|
@@ -743,7 +839,7 @@ module MasterView
|
|
743
839
|
initializer.send(command)
|
744
840
|
initializer
|
745
841
|
end
|
746
|
-
|
842
|
+
|
747
843
|
# Create a new Initializer instance that references the given Configuration
|
748
844
|
# instance.
|
749
845
|
def initialize(config) #:nodoc:
|
@@ -760,14 +856,14 @@ module MasterView
|
|
760
856
|
|
761
857
|
# Load the Masterview configuration settings.
|
762
858
|
# Does *not* load and configure the template engine.
|
763
|
-
#
|
859
|
+
#
|
764
860
|
# Intended for use in testing.
|
765
861
|
def initialize_configuration
|
766
862
|
#?? return if MasterView.const_defined?(:ConfigSettings) ??
|
767
863
|
#ISSUE: support format_datetime option on the logger settings?? [DJL 30-Jul-2006]
|
768
|
-
configuration.initialization_messages << [ :info,
|
864
|
+
configuration.initialization_messages << [ :info,
|
769
865
|
"Initializing MasterView configuration (#{DateTime.now.strftime('%Y-%m-%d %H:%M')})" ]
|
770
|
-
configuration.initialization_messages << [ :info,
|
866
|
+
configuration.initialization_messages << [ :info,
|
771
867
|
"Program name = #{$PROGRAM_NAME}" ] # log the program that is starting the session
|
772
868
|
load_config_settings
|
773
869
|
ensure_valid_settings
|
@@ -779,7 +875,7 @@ module MasterView
|
|
779
875
|
MasterView.const_set('ConfigSettings', configuration)
|
780
876
|
end
|
781
877
|
|
782
|
-
# Load configuration settings from <tt>{config.config_dir_path}/settings.rb</tt>
|
878
|
+
# Load configuration settings from <tt>{config.config_dir_path}/settings.rb</tt>
|
783
879
|
# and <tt>{config.config_dir_path}/environments/{config.environment}.rb</tt>.
|
784
880
|
def load_config_settings #:nodoc:
|
785
881
|
load_app_settings
|
@@ -791,7 +887,7 @@ module MasterView
|
|
791
887
|
load_settings_file(configuration.app_settings_path)
|
792
888
|
end
|
793
889
|
|
794
|
-
# Loads config settings for the environment specified by
|
890
|
+
# Loads config settings for the environment specified by
|
795
891
|
# Configuration#environment_path, which
|
796
892
|
# is typically one of development, testing, or production.
|
797
893
|
def load_environment_settings #:nodoc:
|
@@ -835,7 +931,7 @@ module MasterView
|
|
835
931
|
|
836
932
|
# Rails application options
|
837
933
|
if config.on_rails?
|
838
|
-
# ensure we don't activate runtime reparsing if we didn't autoparse at startup
|
934
|
+
# ensure we don't activate runtime reparsing if we didn't autoparse at startup
|
839
935
|
# (?overzealous? But this what we're currently asserting as the intended behavior in the docs)
|
840
936
|
if not config.parse_masterview_templates_at_startup
|
841
937
|
config.reparse_changed_masterview_templates = false
|
@@ -895,8 +991,8 @@ module MasterView
|
|
895
991
|
# Complete installation of masterview after its own code has been loaded
|
896
992
|
def complete_plugin_installation #:nodoc:
|
897
993
|
#?? return if MasterView.const_defined?(:Initialized) ??
|
898
|
-
MasterView::DirectiveRegistry.register_default_namespaces(
|
899
|
-
configuration.namespace_prefix,
|
994
|
+
MasterView::DirectiveRegistry.register_default_namespaces(
|
995
|
+
configuration.namespace_prefix,
|
900
996
|
configuration.namespace_prefix_extensions )
|
901
997
|
initialize_logger
|
902
998
|
initialize_mio
|
@@ -925,14 +1021,14 @@ module MasterView
|
|
925
1021
|
# all root_path directory anchor points for I/O are expanded absolute paths
|
926
1022
|
io_mgr = MIO::MIOTrees.new
|
927
1023
|
template_extension = File.extname( config.template_filename_pattern )
|
928
|
-
io_mgr.template = MIO::FileMIOTree.new( config.template_src_dir_path, template_extension,
|
1024
|
+
io_mgr.template = MIO::FileMIOTree.new( config.template_src_dir_path, template_extension,
|
929
1025
|
:escape_erb => DefaultParserOptions[:escape_erb], # use DefaultParserOptions since already has config merged
|
930
|
-
:tidy => DefaultParserOptions[:tidy],
|
1026
|
+
:tidy => DefaultParserOptions[:tidy],
|
931
1027
|
:default_generate => DefaultParserOptions[:default_generate],
|
932
1028
|
#TODO: expose the following in Configuration.default_parser_options and document
|
933
|
-
:caching => false,
|
1029
|
+
:caching => false,
|
934
1030
|
:logging => true )
|
935
|
-
|
1031
|
+
|
936
1032
|
if config.generate_rhtml_files
|
937
1033
|
io_mgr.erb = MIO::FileMIOTree.new( config.template_dst_dir_path, config.generated_file_default_extension, :logging => true)
|
938
1034
|
else
|
@@ -1007,7 +1103,7 @@ module MasterView
|
|
1007
1103
|
end
|
1008
1104
|
end
|
1009
1105
|
|
1010
|
-
# Fires the user-supplied after_initialize block (Configuration#after_initialize)
|
1106
|
+
# Fires the user-supplied after_initialize block (Configuration#after_initialize)
|
1011
1107
|
def after_initialize #:nodoc:
|
1012
1108
|
configuration.after_initialize_block.call if configuration.after_initialize_block
|
1013
1109
|
end
|