masterview 0.2.2 → 0.2.3

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 (41) hide show
  1. data/CHANGELOG +14 -0
  2. data/RELEASE_NOTES +12 -0
  3. data/TODO +16 -1
  4. data/doc/configuration.html +19 -8
  5. data/doc/directives.html +173 -4
  6. data/doc/guide.html +2 -2
  7. data/doc/index.html +2 -2
  8. data/doc/stylesheets/masterview.css +13 -0
  9. data/examples/rails_app_config/masterview/environment/development.rb +2 -2
  10. data/lib/masterview/attr_string_parser.rb +105 -0
  11. data/lib/masterview/directive_base.rb +146 -14
  12. data/lib/masterview/directive_helpers.rb +22 -8
  13. data/lib/masterview/directive_registry.rb +169 -0
  14. data/lib/masterview/directives/check_box.rb +31 -0
  15. data/lib/masterview/directives/collection_select.rb +44 -0
  16. data/lib/masterview/directives/hidden_field.rb +2 -2
  17. data/lib/masterview/directives/image_tag.rb +4 -1
  18. data/lib/masterview/directives/insert_generated_comment.rb +7 -6
  19. data/lib/masterview/directives/javascript_include.rb +4 -1
  20. data/lib/masterview/directives/password_field.rb +2 -2
  21. data/lib/masterview/directives/radio_button.rb +35 -0
  22. data/lib/masterview/directives/select.rb +38 -0
  23. data/lib/masterview/directives/stylesheet_link.rb +4 -1
  24. data/lib/masterview/directives/text_area.rb +2 -2
  25. data/lib/masterview/directives/text_field.rb +2 -2
  26. data/lib/masterview/extras/app/controllers/masterview_controller.rb +46 -59
  27. data/lib/masterview/extras/app/views/layouts/masterview_admin.rhtml +73 -0
  28. data/lib/masterview/extras/app/views/masterview/admin/configuration.rhtml +1 -0
  29. data/lib/masterview/extras/app/views/masterview/admin/list.rhtml +1 -1
  30. data/lib/masterview/initializer.rb +73 -20
  31. data/lib/masterview/masterview_info.rb +117 -0
  32. data/lib/masterview/masterview_version.rb +1 -1
  33. data/lib/masterview/parser.rb +22 -35
  34. data/lib/masterview/plugin_load_tracking.rb +17 -8
  35. data/lib/masterview.rb +3 -0
  36. data/test/fixtures/configs/fake_rails_app_with_config/config/masterview/environments/production.rb +5 -1
  37. data/test/unit/config_settings_test.rb +16 -4
  38. data/test/unit/directive_base_test.rb +29 -0
  39. data/test/unit/directive_helpers_parse_test.rb +324 -0
  40. data/test/unit/template_test.rb +242 -0
  41. metadata +14 -2
@@ -1,10 +1,21 @@
1
1
  module MasterView
2
2
 
3
- # mix this in so that these become class methods
4
- # mix in like so
3
+ # Mixin for directive implementation classes which
4
+ # automatically registers a directive implementation class
5
+ # in the MasterView directives registry.
6
+ #
7
+ # Subclasses of MasterView::DirectiveBase inherit this mechanism
8
+ # and will be registered automatically without additional
9
+ # action on the part of the class developer.
10
+ #
11
+ # If you are implementing a directive without subclassing
12
+ # MasterView::DirectiveBase, mix this module into your directive
13
+ # class by using the standard Ruby <code>include</code> statement.
14
+ #
5
15
  # class FooPluginBase
6
16
  # include PluginLoadTracking
7
17
  # end
18
+ #
8
19
  module PluginLoadTracking
9
20
 
10
21
  module InstanceMethods
@@ -12,7 +23,6 @@ module MasterView
12
23
  end
13
24
 
14
25
  module ClassMethods
15
- @@loaded_classes = []
16
26
 
17
27
  # called when a class inherits from this
18
28
  def inherited(plugin_class)
@@ -21,11 +31,10 @@ module MasterView
21
31
 
22
32
  # register a loaded class, called from inherited and can be called manually.
23
33
  def register_class(plugin_class)
24
- @@loaded_classes << plugin_class
25
- end
26
-
27
- def loaded_classes
28
- @@loaded_classes
34
+ #ISSUE: do we really need both PluginLoadTracking.register_class
35
+ #and DirectiveBase.register_directive, in addition to MasterView.register_directive???
36
+ #[DJL 04-Jul-2006]
37
+ MasterView.register_directive(plugin_class)
29
38
  end
30
39
 
31
40
  end
data/lib/masterview.rb CHANGED
@@ -91,13 +91,16 @@ end
91
91
 
92
92
  #internal requires
93
93
  require 'masterview/masterview_version'
94
+ require 'masterview/masterview_info'
94
95
  require 'masterview/pathname_extensions'
95
96
  require 'masterview/filter_helpers'
96
97
  require 'masterview/mtime_tracking_hash'
97
98
  require 'masterview/io'
98
99
  require 'masterview/keyword_expander'
99
100
  require 'masterview/string_extensions'
101
+ require 'masterview/directive_registry'
100
102
  require 'masterview/plugin_load_tracking'
103
+ require 'masterview/attr_string_parser'
101
104
  require 'masterview/directive_helpers'
102
105
  require 'masterview/directive_base'
103
106
  require 'masterview/parser'
@@ -7,5 +7,9 @@
7
7
  #
8
8
 
9
9
  # set production-mode config settings here
10
+
11
+ # enable tidy in this app's production environment
12
+ config.default_parser_options[:tidy] = true
13
+
10
14
  # Only use the MasterView admin pages for development
11
- config.enable_admin_pages = false
15
+ #config.enable_admin_pages = false
@@ -78,7 +78,7 @@ class TestConfiguration < Test::Unit::TestCase
78
78
  # rails application options
79
79
  assert config.parse_masterview_templates_at_startup, 'template parsing at startup should be on by default for a rails app'
80
80
  assert ! config.reparse_changed_masterview_templates, 'reparsing changed templates is only supported when actually running on rails'
81
- assert ! config.enable_admin_pages
81
+ assert ! config.enable_admin_pages, 'MV Admin pages by default are only enabled for development'
82
82
  end
83
83
 
84
84
  def test_config_settings_rails_app
@@ -107,7 +107,11 @@ class TestConfiguration < Test::Unit::TestCase
107
107
  # rails application options
108
108
  assert config.parse_masterview_templates_at_startup, 'template parsing at startup should be on by default for a rails app'
109
109
  assert ! config.reparse_changed_masterview_templates, 'reparsing changed templates is only supported when actually running on rails'
110
- assert ! config.enable_admin_pages
110
+ assert ! config.enable_admin_pages, 'MV Admin pages by default are only enabled for development'
111
+
112
+ # check a setting that we only enabled in production for this app's MV config
113
+ assert ! config.default_parser_options[:tidy], 'We turned on tidy for this app specifically in production'
114
+
111
115
  end
112
116
 
113
117
  def test_config_settings_rails_app_development
@@ -137,7 +141,11 @@ class TestConfiguration < Test::Unit::TestCase
137
141
  # rails application options
138
142
  assert config.parse_masterview_templates_at_startup, 'template parsing at startup should be on by default for a rails app'
139
143
  #assert config.reparse_changed_masterview_templates, 'reparsing changed templates is enabled by default in development mode'
140
- assert ! config.enable_admin_pages
144
+ assert config.enable_admin_pages, 'MV Admin pages by default are enabled for development'
145
+
146
+ # check a setting that we only enabled in production for this app's MV config
147
+ assert ! config.default_parser_options[:tidy], 'We turned on tidy for this app specifically in production'
148
+
141
149
  end
142
150
 
143
151
  def test_config_settings_rails_app_production
@@ -166,7 +174,11 @@ class TestConfiguration < Test::Unit::TestCase
166
174
  # rails application options
167
175
  assert config.parse_masterview_templates_at_startup, 'template parsing at startup should be on by default for a rails app'
168
176
  #assert config.reparse_changed_masterview_templates, 'reparsing changed templates is enabled by default in development mode'
169
- assert ! config.enable_admin_pages, 'this app doesn\'t want the MasterView admin pages in the production site'
177
+ assert ! config.enable_admin_pages, 'MV Admin pages by default are enabled only for development'
178
+
179
+ # check a setting that we only enabled in production for this app's MV config
180
+ assert config.default_parser_options[:tidy], 'We turned on tidy for this app specifically in production'
181
+
170
182
  end
171
183
 
172
184
  end
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ currentPath = File.dirname(__FILE__)
5
+ require File.join( currentPath, '../../lib/masterview' )
6
+
7
+ class TestDirectiveBase < Test::Unit::TestCase
8
+ def setup
9
+ @base = MasterView::DirectiveBase.new('')
10
+ end
11
+
12
+ def test_quote
13
+ assert_equal '\'hello\'', @base.quote('hello')
14
+ end
15
+
16
+ def test_quote_if
17
+ assert_equal '\'helloWorld0123\'', @base.quote_if('helloWorld0123')
18
+ assert_equal 'hello world', @base.quote_if('hello world')
19
+ assert_equal 'hello,world', @base.quote_if('hello,world')
20
+ assert_equal 'hello(world)', @base.quote_if('hello(world)')
21
+ assert_equal ':hello', @base.quote_if(':hello')
22
+ assert_equal '\"hello world\"', @base.quote_if('\"hello world\"')
23
+ assert_equal '%q{helloworld}', @base.quote_if('%q{helloworld}')
24
+ assert_equal 'hello.world', @base.quote_if('hello.world')
25
+ assert_equal 'hel/lo.w_orld', @base.quote_if('hel/lo.w_orld')
26
+ assert_equal '\'\'', @base.quote_if('')
27
+ end
28
+
29
+ end
@@ -0,0 +1,324 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ currentPath = File.dirname(__FILE__)
5
+ require File.join( currentPath, '../../lib/masterview' )
6
+
7
+ class TestDirectiveHelpersParse < Test::Unit::TestCase
8
+ include MasterView::DirectiveHelpers
9
+
10
+ def test_parse_a
11
+ str = <<-END
12
+ a,b,'c'
13
+ END
14
+ assert_equal ['a','b',"'c'"], parse(str.strip)
15
+ end
16
+
17
+ def test_parse_a2
18
+ str = <<-END
19
+ 'a','b','c'
20
+ END
21
+ assert_equal ["'a'","'b'","'c'"], parse(str.strip)
22
+ end
23
+
24
+ def test_parse_a3
25
+ str = <<-END
26
+ "a","b","c"
27
+ END
28
+ assert_equal ['"a"','"b"','"c"'], parse(str.strip)
29
+ end
30
+
31
+ def test_parse_b
32
+ str = <<-END
33
+ a,%q{hello,world},c
34
+ END
35
+ assert_equal ['a','%q{hello,world}','c'], parse(str.strip)
36
+ end
37
+
38
+ def test_parse_c
39
+ str = <<-END
40
+ a,%q[hello,world],c
41
+ END
42
+ assert_equal ['a','%q[hello,world]','c'], parse(str.strip)
43
+ end
44
+
45
+ def test_parse_d
46
+ str = <<-END
47
+ a,%q|hello,world|,c
48
+ END
49
+ assert_equal ['a','%q|hello,world|','c'], parse(str.strip)
50
+ end
51
+
52
+ def test_parse_e
53
+ str = <<-END
54
+ a,%q(hello,world),c
55
+ END
56
+ assert_equal ['a','%q(hello,world)','c'], parse(str.strip)
57
+ end
58
+
59
+ def test_parse_e2
60
+ str = <<-END
61
+ a,%q<hello,world>,c
62
+ END
63
+ assert_equal ['a','%q<hello,world>','c'], parse(str.strip)
64
+ end
65
+
66
+ def test_parse_e3
67
+ str = <<-END
68
+ a,%q_hello,world_,c
69
+ END
70
+ assert_equal ['a','%q_hello,world_','c'], parse(str.strip)
71
+ end
72
+
73
+ def test_parse_e4
74
+ str = <<-END
75
+ a,%q hello,world ,c
76
+ END
77
+ assert_equal ['a','%q hello,world','c'], parse(str.strip)
78
+ end
79
+
80
+ def test_parse_e5
81
+ str = <<-END
82
+ a,%q*hello,world*,c
83
+ END
84
+ assert_equal ['a','%q*hello,world*','c'], parse(str.strip)
85
+ end
86
+
87
+ def test_parse_e6
88
+ str = <<-END
89
+ a,%q!hello,world!,c
90
+ END
91
+ assert_equal ['a','%q!hello,world!','c'], parse(str.strip)
92
+ end
93
+
94
+ def test_parse_e7
95
+ str = <<-END
96
+ a,%q0hello,world0,c
97
+ END
98
+ assert_equal ['a','%q0hello','world0','c'], parse(str.strip)
99
+ end
100
+
101
+ def test_parse_e8
102
+ str = <<-END
103
+ a,%qahello,worlda,c
104
+ END
105
+ assert_equal ['a','%qahello','worlda','c'], parse(str.strip)
106
+ end
107
+
108
+ def test_parse_e9
109
+ str = <<-END
110
+ a,%qBhello,worldB,c
111
+ END
112
+ assert_equal ['a','%qBhello','worldB','c'], parse(str.strip)
113
+ end
114
+
115
+ def test_parse_f
116
+ str = <<-END
117
+ a,%Q{hello,world},c
118
+ END
119
+ assert_equal ['a','%Q{hello,world}','c'], parse(str.strip)
120
+ end
121
+
122
+ def test_parse_g
123
+ str = <<-END
124
+ a,%Q[hello,world],c
125
+ END
126
+ assert_equal ['a','%Q[hello,world]','c'], parse(str.strip)
127
+ end
128
+
129
+ def test_parse_h
130
+ str = <<-END
131
+ a,%Q|hello,world|,c
132
+ END
133
+ assert_equal ['a','%Q|hello,world|','c'], parse(str.strip)
134
+ end
135
+
136
+ def test_parse_i
137
+ str = <<-END
138
+ a,%Q(hello,world),c
139
+ END
140
+ assert_equal ['a','%Q(hello,world)','c'], parse(str.strip)
141
+ end
142
+
143
+ def test_parse_i2
144
+ str = <<-END
145
+ a,%Q<hello,world>,c
146
+ END
147
+ assert_equal ['a','%Q<hello,world>','c'], parse(str.strip)
148
+ end
149
+
150
+ def test_parse_j
151
+ str = <<-END
152
+ a,[1,2, 3],c
153
+ END
154
+ assert_equal ['a','[1,2, 3]','c'], parse(str.strip)
155
+ end
156
+
157
+ def test_parse_j
158
+ str = <<-END
159
+ a,[1,2, 3],[4,5,6]
160
+ END
161
+ assert_equal ['a','[1,2, 3]','[4,5,6]'], parse(str.strip)
162
+ end
163
+
164
+ def test_parse_k
165
+ str = <<-END
166
+ a,{:a => :b, :c => :d}, {:e => 'f', :g => 1}
167
+ END
168
+ assert_equal ['a','{:a => :b, :c => :d}','{:e => \'f\', :g => 1}'], parse(str.strip)
169
+ end
170
+
171
+ def test_parse_l
172
+ str = <<-END
173
+ a,{:a => :b, :c => :d}, :e => 'f', :g => 1
174
+ END
175
+ assert_equal ['a','{:a => :b, :c => :d}',':e => \'f\', :g => 1'], parse(str.strip)
176
+ end
177
+
178
+ def test_parse_l
179
+ str = <<-END
180
+ a,{:a => :b, :c => :d}, :e => 'f', :g => 1
181
+ END
182
+ assert_equal ['a','{:a => :b, :c => :d}',':e => \'f\', :g => 1'], parse(str.strip)
183
+ end
184
+
185
+ def test_parse_m
186
+ str = <<-END
187
+ a,%r{hello,world},c
188
+ END
189
+ assert_equal ['a','%r{hello,world}','c'], parse(str.strip)
190
+ end
191
+
192
+ def test_parse_n
193
+ str = <<-END
194
+ a,%r[hello,world],c
195
+ END
196
+ assert_equal ['a','%r[hello,world]','c'], parse(str.strip)
197
+ end
198
+
199
+ def test_parse_o
200
+ str = <<-END
201
+ a,%r|hello,world|,c
202
+ END
203
+ assert_equal ['a','%r|hello,world|','c'], parse(str.strip)
204
+ end
205
+
206
+ def test_parse_p
207
+ str = <<-END
208
+ a,%r(hello,world),c
209
+ END
210
+ assert_equal ['a','%r(hello,world)','c'], parse(str.strip)
211
+ end
212
+
213
+ def test_parse_q
214
+ str = <<-END
215
+ a,%w{hello, world},c
216
+ END
217
+ assert_equal ['a','%w{hello, world}','c'], parse(str.strip)
218
+ end
219
+
220
+ def test_parse_r
221
+ str = <<-END
222
+ a,%w[hello, world],c
223
+ END
224
+ assert_equal ['a','%w[hello, world]','c'], parse(str.strip)
225
+ end
226
+
227
+ def test_parse_s
228
+ str = <<-END
229
+ a,%w|hello, world|,c
230
+ END
231
+ assert_equal ['a','%w|hello, world|','c'], parse(str.strip)
232
+ end
233
+
234
+ def test_parse_t
235
+ str = <<-END
236
+ a,%w(hello, world),c
237
+ END
238
+ assert_equal ['a','%w(hello, world)','c'], parse(str.strip)
239
+ end
240
+
241
+ def test_parse_u
242
+ str = <<-END
243
+ a,Product.find(:all).collect{|p| [p.name, p.id]},c
244
+ END
245
+ assert_equal ['a','Product.find(:all).collect{|p| [p.name, p.id]}','c'], parse(str.strip)
246
+ end
247
+
248
+ def test_parse_v
249
+ str = <<-END
250
+ a,{:a => :b, :c => [1,2]}, :e => [3,:g], 'h,i' => [j,k]
251
+ END
252
+ assert_equal ['a','{:a => :b, :c => [1,2]}',':e => [3,:g], \'h,i\' => [j,k]'], parse(str.strip)
253
+ end
254
+
255
+ def test_parse_w
256
+ str = <<-END
257
+ END
258
+ assert_equal [], parse(str.strip)
259
+ end
260
+
261
+ def test_parse_x
262
+ str = <<-END
263
+ a,%(hello, world),c
264
+ END
265
+ assert_equal ['a','%(hello, world)','c'], parse(str.strip)
266
+ end
267
+
268
+ def test_parse_x2
269
+ str = <<-END
270
+ a,%{hello, world},c
271
+ END
272
+ assert_equal ['a','%{hello, world}','c'], parse(str.strip)
273
+ end
274
+
275
+ def test_parse_x3
276
+ str = <<-END
277
+ a,%[hello, world],c
278
+ END
279
+ assert_equal ['a','%[hello, world]','c'], parse(str.strip)
280
+ end
281
+
282
+ def test_parse_x4
283
+ str = <<-END
284
+ a,%<hello, world>,c
285
+ END
286
+ assert_equal ['a','%<hello, world>','c'], parse(str.strip)
287
+ end
288
+
289
+ def test_parse_y
290
+ str = <<-END
291
+ a,%s(hello, world),c
292
+ END
293
+ assert_equal ['a','%s(hello, world)','c'], parse(str.strip)
294
+ end
295
+
296
+ def test_parse_z
297
+ str = <<-END
298
+ a,"hello, world",c
299
+ END
300
+ assert_equal ['a','"hello, world"','c'], parse(str.strip)
301
+ end
302
+
303
+ def test_parse_z0
304
+ str = <<-END
305
+ a,'hello, world',c
306
+ END
307
+ assert_equal ['a','\'hello, world\'','c'], parse(str.strip)
308
+ end
309
+
310
+ def test_parse_z1
311
+ str = <<-END
312
+ a,"hello, \\"world",c
313
+ END
314
+ assert_equal ['a',"\"hello, \\\"world\"",'c'], parse(str.strip)
315
+ end
316
+
317
+ def test_parse_z2
318
+ str = <<-END
319
+ a,'hello, \\'world',c
320
+ END
321
+ assert_equal ['a','\'hello, \\\'world\'','c'], parse(str.strip)
322
+ end
323
+
324
+ end