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.
Files changed (29) hide show
  1. data/CHANGELOG +9 -0
  2. data/RELEASE_NOTES +8 -1
  3. data/Rakefile +0 -1
  4. data/TODO +9 -0
  5. data/doc/configuration.html +18 -0
  6. data/doc/directives.html +8 -0
  7. data/examples/rails_app_admin_auth/admin_auth_mixin.rb +47 -0
  8. data/examples/rails_app_config/masterview/settings.rb +11 -6
  9. data/lib/masterview/attr_string_parser.rb +6 -4
  10. data/lib/masterview/directive_registry.rb +3 -2
  11. data/lib/masterview/directives/.metadata +2 -2
  12. data/lib/masterview/directives/attr.rb +12 -7
  13. data/lib/masterview/extras/admin_auth_mixin.rb +49 -0
  14. data/lib/masterview/extras/app/controllers/masterview_controller.rb +21 -13
  15. data/lib/masterview/extras/app/views/layouts/masterview_admin.rhtml +4 -2
  16. data/lib/masterview/extras/app/views/layouts/masterview_admin_config.rhtml +4 -2
  17. data/lib/masterview/extras/app/views/masterview/admin/create.rhtml +2 -2
  18. data/lib/masterview/extras/app/views/masterview/admin/interact.rhtml +2 -2
  19. data/lib/masterview/extras/app/views/masterview/admin/view_rhtml.rhtml +2 -2
  20. data/lib/masterview/extras/init_mv_admin_pages.rb +52 -0
  21. data/lib/masterview/initializer.rb +224 -128
  22. data/lib/masterview/masterview_version.rb +1 -1
  23. data/lib/masterview/rails_ext/action_view_erb_direct.rb +102 -45
  24. data/test/fixtures/deprecated_directive_base_directives/submit.rb +17 -0
  25. data/test/unit/attr_string_parser_test.rb +14 -7
  26. data/test/unit/directive_insert_generated_comment_test.rb +1 -1
  27. data/test/unit/directive_link_to_test.rb +12 -0
  28. data/test/unit/template_test.rb +111 -0
  29. metadata +11 -6
data/CHANGELOG CHANGED
@@ -1,3 +1,12 @@
1
+ 0.3.2 - February 20, 2007
2
+ Fix bug in mv:attr directive where multiparam eval method like :a => #{hello 1,2} was not being parsed properly
3
+ Added mv:select to alphabetical list on bottom of directives html doc page
4
+ Fix incompatibility with Rails 1.2 template error - blank page on erb error
5
+ Use template_changed_since? for compile checking when it is available Rails changeset 5587
6
+ Added config.admin_auth_mixin allowing configurable authorization for masterview admin
7
+ Change generator to use request, flash, params rather than @request, @flash, @params which are deprecated
8
+ Tested with Rails 1.2.2
9
+
1
10
  0.3.1 - November 20, 2006
2
11
  Fixed problem with deprecated/directive_base was missing registry include
3
12
  Update image_tag docs, indicating that it now simply passes through width and height rather than setting size
data/RELEASE_NOTES CHANGED
@@ -1,11 +1,18 @@
1
1
  = MasterView - Rails-optimized (x)html friendly template engine
2
2
 
3
+ == Recent changes (Release 0.3.2 - Maintenance release plus custom admin auth
4
+ This release addresses a compatibility problem with Rails 1.2 where a view syntax
5
+ error would not display the normal debug output but instead displayed only a blank
6
+ screen. Also fixed a parsing problem with multiple parameters in some directives.
7
+ Added the ability to use custom mixin for authorization to MasterView admin screens.
8
+ Changed the MasterView generator to use request, flash, and params rather than
9
+ deprecated @request, @flash, and @params. Tested with Rails 1.2.2
10
+
3
11
  == Recent changes (Release 0.3.1 - Maintenance release
4
12
  This release addresses an issue with ruby 1.8.5, fixes a problem with the
5
13
  deprecated/directive_base used for custom directives, updates a few out of
6
14
  date docs, and accomodates a change to the API of the Rails 1.2 generator
7
15
 
8
-
9
16
  == Recent changes (Release 0.3.0 - Major update - refactoring of directive API (for developing directives)
10
17
  The directive API for creating directives has been refactored and simplified
11
18
  and improvements have been made to better support directive extensions through
data/Rakefile CHANGED
@@ -265,7 +265,6 @@ PKG_FILES_RELEASE_DOCS = [
265
265
  PKG_FILES_RUNTIME = [
266
266
  "lib/**/*",
267
267
  "lib/**/.metadata",
268
- "directives/**/*", #SHOULD THIS GO AWAY (??)
269
268
  "Rakefile",
270
269
  "init.rb"
271
270
  ]
data/TODO CHANGED
@@ -18,6 +18,9 @@ TODO LIST
18
18
  - run spelling checker on our html and release docs; retrofit to rdoc comments
19
19
  - build utility to auto-generate directives reference doc from directive metadata and std. rdoc markup
20
20
  - add doc on directive impl unit test helper and techniques/examples
21
+ - document directive dir metadata :ignores list option in Developer doc
22
+ - add discussion in Configuration doc on directive load path configuration
23
+ (adding directories, providing metadata overrides)
21
24
  - more tests
22
25
  - build improvements
23
26
  - add release tasks to automate archiving trunk to tags/masterview-N.N.N, resetting tags/masterview
@@ -50,3 +53,9 @@ TODO LIST
50
53
  - more docs and examples about directive API and helpers
51
54
 
52
55
  - sitemesh style directives
56
+
57
+ - not getting good template error messages on latest rails 1.2
58
+
59
+ - link_to can now take simple string as options rather than hash, but the implied name thing causes a problem since we don't know whether name was passed or not
60
+
61
+ - REST generator
@@ -458,6 +458,24 @@ element. If a body tag is present and mv:generate is being added then also add m
458
458
  </td>
459
459
  </tr>
460
460
  <tr>
461
+ <td class="setting">admin_auth_mixin</td>
462
+ <td class="default">Built-in local machine check (local_request?)</td>
463
+ <td class="description">Defines custom MV Admin authorization method and module.
464
+ <div class="explanation">
465
+ Automatically loads app/masterview/admin_auth_mixin.rb if present.
466
+ <pre>
467
+ config.admin_auth_mixin = {
468
+ :file => 'admin_auth_mixin', # require file in app/masterview
469
+ :file_loc => nil # :RAILS_ROOT or root dir path for alt load load
470
+ :module => :MasterViewAdminAuthMixin, # mixin module name
471
+ }
472
+
473
+ see examples/rails_app_admin_auth/auth_local_request_mixin.rb for more details
474
+ </pre>
475
+ </div>
476
+ </td>
477
+ </tr>
478
+ <tr>
461
479
  <td class="setting">enable_admin_pages</td>
462
480
  <td class="default">true for development, otherwise false</td>
463
481
  <td class="description">Enable MasterView admin pages in the rails application.
data/doc/directives.html CHANGED
@@ -1374,6 +1374,14 @@ Used on <code>&lt;input&gt;</code> form elements
1374
1374
 
1375
1375
  <!-- s -->
1376
1376
  <tr>
1377
+ <td class="directive"><a href="#mv_select">mv:select</a></td>
1378
+ <td>Replaces this element with a Rails <code>select</code> helper.
1379
+ <span class="explanation">(
1380
+ Used on <code>&lt;select&gt;</code> form elements
1381
+ )</span>
1382
+ </td>
1383
+ </tr>
1384
+ <tr>
1377
1385
  <td class="directive"><a href="#mv_stylesheet_link">mv:stylesheet_link</a></td>
1378
1386
  <td>Replaces this element using the Rails <code>stylesheet_link_tag</code> helper
1379
1387
  <span class="explanation">(
@@ -0,0 +1,47 @@
1
+
2
+ # Example of a MasterView admin custom authorization mixin.
3
+ #
4
+ # This module is included into the MasterviewController, so it has access
5
+ # to all the the standard rails controller facilities as well as
6
+ # any application-specific features in your own ApplicationController.
7
+ #
8
+ # To install a custom authorization handler in your application,
9
+ # copy this file to the app/masterview directory in your rails application
10
+ # and modify the implementation of the allow_access? predicate to
11
+ # perform checking suitable in your application for determining
12
+ # whether to grant access to the MasterView admininstration pages.
13
+ #
14
+ # To change the mixin module name or to load your admin_auth module
15
+ # from a different directory or file name, set the MasterView
16
+ # admin_auth_mixin configuration setting in your config/masterview/settings.rb
17
+ # or an appropriate config/masterview/environments specification.
18
+ #
19
+ # For example, to load an alternate mixin from your app/masterview directory:
20
+ #
21
+ # config.admin_auth_mixin = {
22
+ # :file => 'alt_admin_auth_mixin',
23
+ # :module => :MasterViewAltAdminAuthMixin, # default is MasterViewAdminAuthMixin
24
+ # }
25
+ #
26
+ # To load an auth_check mixin from your rails lib directory:
27
+ #
28
+ # config.admin_auth_mixin = {
29
+ # :file => 'lib/custom_admin_auth_mixin',
30
+ # :file_loc => :RAILS_ROOT,
31
+ # }
32
+ #
33
+ module MasterViewAdminAuthMixin
34
+
35
+ MasterView::Log.debug { 'Using customized admin_auth mixin for MasterView admin (local requests only)' }
36
+
37
+ protected
38
+
39
+ # Check that the current user has authorization to access admin operations.
40
+ def allow_access?
41
+ # default allows only for developer testing on local machine
42
+ local_request?
43
+ end
44
+
45
+ end
46
+
47
+
@@ -1,17 +1,17 @@
1
1
  # Application configuration settings for the MasterView template engine.
2
- #
2
+ #
3
3
  # This code is run at plugin load time, after the base rails framework
4
4
  # has been loaded and configured, but before any application-specific config
5
5
  # in +environment.rb+ is run.
6
- #
6
+ #
7
7
  # The MasterView configuration specification is referenced through +config+.
8
- #
8
+ #
9
9
  # Set standard application configuration options here.
10
10
  # General settings can be overridden for specific environments by providing
11
11
  # additional settings values in +config/masterview/environments/#{environment}.rb+.
12
- #
12
+ #
13
13
  # See Rails::Configuration for details on the available configuration settings.
14
- #
14
+ #
15
15
 
16
16
  # General options - root paths for config settings, directives, templates
17
17
  #config.root_path = RAILS_ROOT
@@ -44,7 +44,7 @@
44
44
  #config.handle_parse_exceptions = true
45
45
  #config.default_parser_options = { :tidy => false, :escape_erb => true }
46
46
  #config.tidy_path = '/usr/lib/libtidy.so' # *nix
47
- #config.tidy_path = 'c:/tidy/lib/tidy.dll' # Win32
47
+ #config.tidy_path = 'c:/tidy/lib/tidy.dll' # Win32
48
48
  #config.namespace_prefix = 'mv:'
49
49
  #config.namespace_prefix_extensions = 'mvx:'
50
50
  #config.inline_erb_start = '{{{'
@@ -54,6 +54,11 @@
54
54
  # Rails application options
55
55
  #config.parse_masterview_templates_at_startup = true
56
56
  #config.reparse_changed_masterview_templates = false # enabled in development env
57
+ #config.admin_auth_mixin = {
58
+ # :file => 'admin_auth_mixin', # require file in app/masterview unless alt :file_loc context specified
59
+ # :file_loc => nil,
60
+ # :module => :MasterViewAdminAuthMixin, # module to mix in to MasterView controller
61
+ #}
57
62
  #config.enable_admin_pages = false
58
63
  #config.enable_view_rhtml = false
59
64
  #config.generate_rhtml_files = false # compile directly to Rails view cache
@@ -17,9 +17,10 @@ module MasterView
17
17
  # returns array of string arguments which are trimmed(stripped) representing the arguments
18
18
  # declared in the attr_value string
19
19
  # handles ([{%'" arguments and embedded quotes
20
- def self.parse(str)
20
+ # if split_implicit_hash is true then splits the hash into args.
21
+ def self.parse(str, split_implicit_hash = false)
21
22
  parser = self.new(str)
22
- parser.parse
23
+ parser.parse(split_implicit_hash)
23
24
  end
24
25
 
25
26
  def initialize(str)
@@ -28,7 +29,8 @@ module MasterView
28
29
  @partial_percent_sequence = nil
29
30
  end
30
31
 
31
- def parse
32
+ # if split_implicit_hash is true then :a => :b, :c => :d will be split into args :a => :b and :c => :d
33
+ def parse(split_implicit_hash = false)
32
34
  args = []
33
35
  s = []
34
36
  implicit_hash = false
@@ -68,7 +70,7 @@ module MasterView
68
70
  push_closing_char(c, false) #not in string
69
71
  when '>'
70
72
  if s.last == '=' && @closing_char_mode_stack.empty? # we are no in closing_char search and we have a => implying the rest is a hash
71
- implicit_hash = true
73
+ implicit_hash = (split_implicit_hash) ? false : true
72
74
  end
73
75
  end
74
76
  end
@@ -225,10 +225,11 @@ module MasterView
225
225
  dir_path = dpe.dir_path
226
226
  #??Log.debug { "Loading directives from #{dir_path} with metadata defaults #{md_defaults.inspect}" }
227
227
  #??load_context[:synonyms] = dir_md_specs.fetch(:synonyms, {})??
228
- #??files_to_ignore = dir_md_specs.fetch(:ignore, []).collect { |fn| fn.ends_with?('.rb') ? fn : "#{fn}.rb" }
228
+ files_to_ignore = dir_md_specs.fetch(:ignore, []).collect { |fn| fn.ends_with?('.rb') ? fn : "#{fn}.rb" }
229
229
  Dir.entries( dir_path ).each { |fn|
230
230
  # we assume all .rb files in a directives dir are directive impls
231
- if fn =~ /[.]rb$/ #?? && ! files_to_ignore.include?(fn)
231
+ if fn =~ /[.]rb$/
232
+ next if files_to_ignore.include?(fn) # skip directives in the ignore list
232
233
  directive_file_path = "#{dir_path}/#{fn}"
233
234
  dir_load_context[:directive_file] = directive_file_path
234
235
  #??@load_context[:directive_synonyms] = dir_synonyms_specs.fetch(fn, [])??
@@ -6,8 +6,8 @@ default:
6
6
  namespace: mv
7
7
  description: Built-in MasterView directive
8
8
 
9
- # optionally specify any .rb files in this directory to ignore
10
- #ignore: []
9
+ # optionally specify name(s) of any .rb files in this directory to ignore
10
+ ignore: []
11
11
 
12
12
  # optionally specify synonyms to register directives
13
13
  # Mainly intended to provide backwards compat (hopefully for short-term transition only...)
@@ -4,7 +4,7 @@ module MasterView
4
4
  # takes the attr_value and parses it as a hash :foo => 'bar', :baz => 'cat'
5
5
  # it sets/overrides the tag's attribute values for each value.
6
6
  # To use erb output simply wrap the content in #{ foo } for example :foo => #{h product.name}
7
- #
7
+ #
8
8
  class Attr < MasterView::DirectiveBase
9
9
  # substitution to make it easy to parse erb in attr
10
10
  SubstForErb = '#'+InlineErbStart+'= \1 '+InlineErbEnd+'#'
@@ -14,12 +14,17 @@ module MasterView
14
14
  :description => 'Replaces attribute value(s) on an element with the value of an expression'
15
15
 
16
16
  event :stag do
17
- attr_value.gsub!( /#\{([^}]*)\}/, SubstForErb ) #taking #{h product.name} and changing to #{{{= h product.name}}}# for easy parsing
18
- arr = attr_value.scan( /:(\w+)\s*=>\s*(['"#])([^,\2]*)\2,?/ )
19
- arr.each do |scn|
20
- n = scn[0]
21
- v = scn[2]
22
- element_attrs[n] = v
17
+ av = attr_value.gsub( /#\{([^}]*)\}/, SubstForErb ) #taking #{h product.name} and changing to #{{{= h product.name}}}# for easy parsing
18
+ av.strip!
19
+ av = av[1..-2] if (av[0,1]=='{' && av[-1,1]=='}') # explicit hash, make it implicit by removing surrounding braces so we can split it
20
+ hash_arr = MasterView::AttrStringParser.parse(av, true) # split_implicit_hash
21
+ hash_arr.each do |hash_kv|
22
+ arr = hash_kv.scan( /:(\w+)\s*=>\s*(['"#])([^\2]*)\2/ )
23
+ arr.each do |scn|
24
+ n = scn[0]
25
+ v = scn[2]
26
+ element_attrs[n] = v
27
+ end
23
28
  end
24
29
  end
25
30
 
@@ -0,0 +1,49 @@
1
+ module MasterView
2
+ module Admin
3
+
4
+ # This module is mixed into the MasterView Admin Controller to provide the default
5
+ # authorization for MasterView admin page access.
6
+ #
7
+ # The authorization method must be a predicate named allow_access?.
8
+ # The mixin is included in an ApplicationController subclass
9
+ # and thus may access all services available to controllers
10
+ # in your application.
11
+ #
12
+ # To override this method, create a module with your auth_check predicate
13
+ # and configure the load specification setting in the config.admin_auth_mixin.
14
+ # Default if not specified is to load admin_auth_mixin.rb from the rails
15
+ # app/masterview directory, if present, and install mixin module MasterViewAdminAuthMixin.
16
+ #
17
+ # example:
18
+ #
19
+ ##config.admin_auth_mixin = {
20
+ # :file => 'admin_auth_mixin', # require file in app/masterview unless alt :file_loc context specified
21
+ # :file_loc => nil,
22
+ # :module => :MasterViewAdminAuthMixin, # module to mix in to MasterView controller
23
+ # }
24
+ #
25
+ module AuthMixin
26
+
27
+ MasterView::Log.info { 'Using default admin_auth mixin for MasterView admin (local requests only)' }
28
+
29
+ protected
30
+
31
+ # Check that the current user has authorization to access admin operations.
32
+ #
33
+ # Default implementation of authorization check
34
+ # restricts access to requests from the local machine (developer testing).
35
+ #
36
+ # An application with a user authorization scheme might do something like
37
+ # verifying that an authenticated login is available and that the current
38
+ # user has permission to perform admin operations:
39
+ #
40
+ # current_user && user_has_perm?('mv-admin')
41
+ #
42
+ def allow_access?
43
+ # default only allow for developer testing on local machine
44
+ local_request?
45
+ end
46
+
47
+ end
48
+ end
49
+ end
@@ -48,7 +48,7 @@ require 'masterview/extras/sample_templates'
48
48
 
49
49
  class MasterviewController < ApplicationController
50
50
  include MasterView::MIO::DefaultGenerateMIOFilter
51
-
51
+ include MasterView::MasterViewAdminAuthMixin
52
52
  before_filter :check_authorization, :except => [ :access_not_allowed ]
53
53
 
54
54
  ###layout 'masterview_admin'
@@ -79,14 +79,17 @@ class MasterviewController < ApplicationController
79
79
  masterview_render_with_layout( 'masterview/admin/configuration', 'masterview_admin_config' )
80
80
  end
81
81
 
82
+ # Describe the installed set of MasterView directives (builtin and addons)
82
83
  def directives
83
84
  masterview_render_with_layout( 'masterview/admin/directives', 'masterview_admin_config' )
84
85
  end
85
86
 
87
+ # Describe the installed set of MasterView features
86
88
  def features
87
89
  masterview_render_with_layout( 'masterview/admin/features', 'masterview_admin_config' )
88
90
  end
89
91
 
92
+ #####move this to someplace accessible!!
90
93
  # Rebuild all templates in the application.
91
94
  # Invoked from the main masterview admin page.
92
95
  def rebuild_all
@@ -121,7 +124,7 @@ class MasterviewController < ApplicationController
121
124
  # Create a new, empty template.
122
125
  # Invoked from the main masterview admin page.
123
126
  def create
124
- if @request.post?
127
+ if request.post?
125
128
  action_to_create = params[:action_name]
126
129
  src_file = params[:file]
127
130
 
@@ -147,7 +150,7 @@ class MasterviewController < ApplicationController
147
150
  smart_render 'masterview/admin/view_rhtml'
148
151
  end
149
152
 
150
- # interact, test template src, view results
153
+ # interactive template editor - parse template source and show generated output
151
154
  def interact
152
155
  @results = []
153
156
  @src = params[:src]
@@ -170,28 +173,33 @@ class MasterviewController < ApplicationController
170
173
  smart_render 'masterview/admin/interact'
171
174
  end
172
175
 
176
+ protected
177
+
178
+ # Check that the current user has authorization to access admin operations
179
+ def check_authorization
180
+ if ! allow_access?
181
+ redirect_to :action => :access_not_allowed
182
+ end
183
+ end
184
+
173
185
  def access_not_allowed #:nodoc:
174
186
  render :text => '<p>We\'re sorry, but the page you have requested is only available to authorized users.</p>',
175
187
  :status => 500
176
188
  end
177
189
 
178
- protected
179
-
190
+ =begin
191
+ # uses the config.admin_check_auth_proc to determine if allowed, override this
192
+ # in config settings. Default restricts to local_request
180
193
  # Default implementation of authorization check
181
- # to restrict access to administrative services
194
+ # restricts access to administrative services
195
+ # to local machine (developer testing)
182
196
  def allow_access?
183
197
  # a more general solution might look something like:
184
198
  # current_user && user_has_perm?('mv-admin')
185
199
  # backstop: only allow for developer testing on local machine
186
200
  local_request?
187
201
  end
188
-
189
- # Check that the current user has authorization to access admin operations
190
- def check_authorization
191
- if ! allow_access?
192
- redirect_to :action => :access_not_allowed
193
- end
194
- end
202
+ =end
195
203
 
196
204
  private
197
205
 
@@ -42,9 +42,11 @@
42
42
  <div class="mv_admin_list content">
43
43
  <h1>MasterView Admin</h1>
44
44
 
45
- <% if @flash[:notice] %>
45
+ <% if flash[:notice] %>
46
+
46
47
  <div class="messages" id="admin_messages">
47
- <%= h @flash[:notice] %>
48
+ <%= h flash[:notice] %>
49
+
48
50
  </div>
49
51
  <% end %>
50
52
 
@@ -46,9 +46,11 @@
46
46
  <h1><%= @config_page_title %></h1>
47
47
  <p><b>MasterView Version:</b> <%= MasterView::VERSION::STRING %><br/></p>
48
48
 
49
- <% if @flash[:notice] %>
49
+ <% if flash[:notice] %>
50
+
50
51
  <div class="messages" id="admin_messages">
51
- <%= h @flash[:notice] %>
52
+ <%= h flash[:notice] %>
53
+
52
54
  </div>
53
55
  <% end %>
54
56