dryml 1.1.0 → 1.3.0.RC

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/taglibs/core.dryml CHANGED
@@ -4,7 +4,9 @@
4
4
  It's the DRYML equivalent of Ruby's `send` method.
5
5
  -->
6
6
  <def tag="call-tag" attrs="tag">
7
- <%= send(tag.gsub('-', '_'), attributes, parameters) %>
7
+ <%= Dryml.static_tags.include?(tag) ?
8
+ content_tag(tag, parameters.default, attributes) :
9
+ send(tag.gsub('-', '_'), attributes, parameters) %>
8
10
  </def>
9
11
 
10
12
 
@@ -15,13 +17,21 @@ Using regular DRYML conditional logic it is rather akward to conditionally wrap
15
17
  ### Usage
16
18
 
17
19
  For example, you might want to wrap an `<img>` tag in an `<a>` tag but only under certain conditions. Say the current context has an `href` attribute that may or may not be nil. We want to wrap the img in `<a>` if `href` is not nil:
18
-
20
+
19
21
  <wrap when="&this.href.present?" tag="a" href="&this.href"><img src="&this.img_filename"/></wrap>
20
- {: .dryml}
22
+ {: .dryml}
21
23
  -->
22
24
  <def tag="wrap" attrs="tag, when, parameter">
23
25
  <% parameter ||= :default %>
24
- <%= when_ ? send(tag, attributes, { parameter.to_sym => parameters[:default] }) : parameters.default %>
26
+ <%= if when_
27
+ if Dryml.static_tags.include?(tag)
28
+ content_tag(tag, parameters.default, attributes)
29
+ else
30
+ send(tag.gsub('-', '_'), attributes, { parameter.to_sym => parameters[:default] })
31
+ end
32
+ else
33
+ parameters.default
34
+ end %>
25
35
  </def>
26
36
 
27
37
 
@@ -31,7 +41,7 @@ For example, you might want to wrap an `<img>` tag in an `<a>` tag but only unde
31
41
 
32
42
  <partial name="my-partial" locals="&{:x => 10, :y => 20}"/>
33
43
  -->
34
- <def tag="partial" attrs="name, locals"><%=
44
+ <def tag="partial" attrs="name, locals"><%=
35
45
  locals ||= {}
36
46
  render(:partial => name, :locals => locals.merge(:this => this))
37
47
  %></def>
@@ -41,13 +51,13 @@ For example, you might want to wrap an `<img>` tag in an `<a>` tag but only unde
41
51
 
42
52
  ### Attributes
43
53
 
44
- - join: The value of this attribute, if given, will be inserted between each of the items (e.g. `join=", "` is very common).
54
+ - join: The value of this attribute, if given, will be inserted between each of the items (e.g. `join=", "` is very common).
45
55
  -->
46
- <def tag="repeat" attrs="join"><if><%=
56
+ <def tag="repeat" attrs="join"><if><%=
47
57
  raise ArgumentError, "Cannot <repeat> on #{this.inspect}" unless this.respond_to? :each
48
58
  context_map do
49
59
  parameters.default
50
- end.join(join)
60
+ end.safe_join(join)
51
61
  %></if></def>
52
62
 
53
63
 
@@ -61,19 +71,19 @@ For example, you might want to wrap an `<img>` tag in an `<a>` tag but only unde
61
71
 
62
72
  ### Usage
63
73
 
64
- <if test="&current_user.administrator?">Logged in as administrator</if>
74
+ <if test="&current_user.administrtator?">Logged in as administrator</if>
65
75
  <else>Logged in as normal user</else>
66
-
67
- **IMPORTANT NOTE**: `<if>` tests for non-blank vs. blank (as defined by ActiveSupport), not true vs. false.
76
+
77
+ **IMPORTANT NOTE**: `<if>` tests for non-blank vs. blank (as defined by ActiveSuport), not true vs. false.
68
78
 
69
79
  If you do not give the `test` attribute, uses the current context instead. This allows a nice trick like this:
70
80
 
71
81
  <if:comments>...</if>
72
-
82
+
73
83
  This has the double effect of changing the context to the `this.comments`, and only evaluating the body if there are comments (because an empty
74
- collection is considered blank)
84
+ collection is considered blank)
75
85
  -->
76
- <def tag="if" attrs="test"><%=
86
+ <def tag="if" attrs="test"><%=
77
87
  test = all_attributes.fetch(:test, this)
78
88
  res = (cond = !test.blank?) ? parameters.default : ""
79
89
  Dryml.last_if = cond
@@ -88,8 +98,8 @@ collection is considered blank)
88
98
 
89
99
 
90
100
  <!-- Same behaviour as `<if>`, except the test is negated. -->
91
- <def tag="unless" attrs="test"><%=
92
- test = all_attributes.fetch(:test, this)
101
+ <def tag="unless" attrs="test"><%=
102
+ test = all_attributes.fetch(:test, this)
93
103
  res = (cond = test.blank?) ? parameters.default : ""
94
104
  Dryml.last_if = cond
95
105
  res
@@ -100,37 +110,37 @@ collection is considered blank)
100
110
  <def tag="fake-field-context" attrs="fake-field, context"><%=
101
111
  res = ""
102
112
  new_field_context(fake_field, context) { res << parameters.default }
103
- res
113
+ raw res
104
114
  %></def>
105
115
 
106
116
 
107
117
  <!-- nodoc. Define core HTML tags defined in Rapid so that DRYML can be used without Rapid. -->
108
- <def tag="html"><%= "<html#{tag_options(attributes)}>" -%><do param="default"/><%= "</html>" -%></def>
118
+ <def tag="html"><%=raw "<html#{tag_options(attributes, true)}>" -%><do param="default"/><%= "</html>" -%></def>
109
119
 
110
120
  <!-- nodoc. Define core HTML tags defined in Rapid so that DRYML can be used without Rapid. -->
111
- <def tag="table"><%= "<table#{tag_options(attributes)}>" -%><do param="default"/><%= "</table>" -%></def>
121
+ <def tag="table"><%=raw "<table#{tag_options(attributes, true)}>" -%><do param="default"/><%= "</table>" -%></def>
112
122
 
113
123
  <!-- nodoc. Define core HTML tags defined in Rapid so that DRYML can be used without Rapid. -->
114
- <def tag="a"><%= "<a#{tag_options(attributes)}>" -%><do param="default"/><%= "</a>" -%></def>
124
+ <def tag="a"><%=raw "<a#{tag_options(attributes, true)}>" -%><do param="default"/><%= "</a>" -%></def>
115
125
 
116
126
  <!-- nodoc. Define core HTML tags defined in Rapid so that DRYML can be used without Rapid. -->
117
- <def tag="section"><%= "<section#{tag_options(attributes)}>" -%><do param="default"/><%= "</section>" -%></def>
127
+ <def tag="section"><%=raw "<section#{tag_options(attributes, true)}>" -%><do param="default"/><%= "</section>" -%></def>
118
128
 
119
129
  <!-- nodoc. Define core HTML tags defined in Rapid so that DRYML can be used without Rapid. -->
120
- <def tag="header"><%= "<header#{tag_options(attributes)}>" -%><do param="default"/><%= "</header>" -%></def>
130
+ <def tag="header"><%=raw "<header#{tag_options(attributes, true)}>" -%><do param="default"/><%= "</header>" -%></def>
121
131
 
122
132
  <!-- nodoc. Define core HTML tags defined in Rapid so that DRYML can be used without Rapid. -->
123
- <def tag="footer"><%= "<footer#{tag_options(attributes)}>" -%><do param="default"/><%= "</footer>" -%></def>
133
+ <def tag="footer"><%=raw "<footer#{tag_options(attributes, true)}>" -%><do param="default"/><%= "</footer>" -%></def>
124
134
 
125
135
  <!-- nodoc. Define core HTML tags defined in Rapid so that DRYML can be used without Rapid. -->
126
- <def tag="form"><%= "<form#{tag_options(attributes)}>" -%><do param="default"/><%= "</form>" -%></def>
136
+ <def tag="form"><%=raw "<form#{tag_options(attributes, true)}>" -%><do param="default"/><%= "</form>" -%></def>
127
137
 
128
138
  <!-- nodoc. Define core HTML tags defined in Rapid so that DRYML can be used without Rapid. -->
129
- <def tag="submit"><%= "<submit#{tag_options(attributes)}>" -%><do param="default"/><%= "</submit>" -%></def>
139
+ <def tag="submit"><%=raw "<submit#{tag_options(attributes, true)}>" -%><do param="default"/><%= "</submit>" -%></def>
130
140
 
131
141
  <!-- nodoc. Define core HTML tags defined in Rapid so that DRYML can be used without Rapid. -->
132
- <def tag="input"><%= "<input#{tag_options(attributes)}>" -%><do param="default"/><%= "</input>" -%></def>
142
+ <def tag="input"><%=raw "<input#{tag_options(attributes, true)}>" -%><do param="default"/><%= "</input>" -%></def>
133
143
 
134
144
  <!-- nodoc. Define core HTML tags defined in Rapid so that DRYML can be used without Rapid. -->
135
- <def tag="link"><%= "<link#{tag_options(attributes)}>" -%><do param="default"/><%= "</link>" -%></def>
145
+ <def tag="link"><%=raw "<link#{tag_options(attributes, true)}>" -%><do param="default"/><%= "</link>" -%></def>
136
146
 
data/test/dryml.rdoctest CHANGED
@@ -3,12 +3,11 @@
3
3
  >> require 'active_support'
4
4
  >> require 'action_view'
5
5
  >> require 'action_controller'
6
- >> $:.unshift File.join(File.expand_path(File.dirname(__FILE__)), '../../hobosupport/lib')
6
+ >> $:.unshift File.join(File.expand_path(File.dirname(__FILE__)), '../../hobo_support/lib')
7
7
  >> $:.unshift File.join(File.expand_path(File.dirname(__FILE__)), '../../dryml/lib')
8
- >> require 'hobosupport'
8
+ >> require 'hobo_support'
9
9
  >> require 'dryml'
10
- >> require 'dryml/template_handler'
11
- >> Dryml.enable
10
+ >> require 'dryml/railtie/template_handler'
12
11
 
13
12
  {.hidden}
14
13
 
@@ -35,11 +34,11 @@
35
34
 
36
35
  This triggers bug #452, so disabled. FIXME.
37
36
 
38
- #>>
37
+ #>>
39
38
  Dryml.render(%q{<def tag="myp">
40
39
  <p param="default"/>
41
40
  </def>
42
- <extend tag="myp">
41
+ <extend tag="myp">
43
42
  <old-myp merge>
44
43
  <default: replace>Hello <default: restore/></default:>
45
44
  </old-myp>
metadata CHANGED
@@ -1,13 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dryml
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
5
- prerelease:
6
- segments:
7
- - 1
8
- - 1
9
- - 0
10
- version: 1.1.0
4
+ prerelease: 6
5
+ version: 1.3.0.RC
11
6
  platform: ruby
12
7
  authors:
13
8
  - Tom Locke
@@ -15,69 +10,63 @@ autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
12
 
18
- date: 2011-11-15 00:00:00 -05:00
13
+ date: 2011-05-10 00:00:00 -04:00
19
14
  default_executable:
20
15
  dependencies:
21
16
  - !ruby/object:Gem::Dependency
22
- name: hobosupport
17
+ name: actionpack
23
18
  prerelease: false
24
19
  requirement: &id001 !ruby/object:Gem::Requirement
25
20
  none: false
26
21
  requirements:
27
- - - "="
22
+ - - ~>
28
23
  - !ruby/object:Gem::Version
29
- hash: 19
30
- segments:
31
- - 1
32
- - 1
33
- - 0
34
- version: 1.1.0
24
+ version: 3.0.0
35
25
  type: :runtime
36
26
  version_requirements: *id001
37
27
  - !ruby/object:Gem::Dependency
38
- name: actionpack
28
+ name: hobo_support
39
29
  prerelease: false
40
30
  requirement: &id002 !ruby/object:Gem::Requirement
41
31
  none: false
42
32
  requirements:
43
- - - ">="
44
- - !ruby/object:Gem::Version
45
- hash: 3
46
- segments:
47
- - 2
48
- - 2
49
- - 2
50
- version: 2.2.2
51
- - - <
33
+ - - "="
52
34
  - !ruby/object:Gem::Version
53
- hash: 7
54
- segments:
55
- - 3
56
- - 0
57
- - 0
58
- version: 3.0.0
35
+ version: 1.3.0.RC
59
36
  type: :runtime
60
37
  version_requirements: *id002
61
- description:
38
+ - !ruby/object:Gem::Dependency
39
+ name: rubydoctest
40
+ prerelease: false
41
+ requirement: &id003 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: "0"
47
+ type: :development
48
+ version_requirements: *id003
49
+ description: The Don't Repeat Yourself Markup Language
62
50
  email: tom@tomlocke.com
63
51
  executables: []
64
52
 
65
53
  extensions: []
66
54
 
67
- extra_rdoc_files:
68
- - README
55
+ extra_rdoc_files: []
56
+
69
57
  files:
70
58
  - CHANGES.txt
71
59
  - LICENSE.txt
72
60
  - README
73
61
  - Rakefile
74
62
  - TODO.txt
63
+ - VERSION
75
64
  - dryml.gemspec
76
65
  - lib/dryml.rb
77
66
  - lib/dryml/dryml_builder.rb
78
67
  - lib/dryml/dryml_doc.rb
79
68
  - lib/dryml/dryml_generator.rb
80
- - lib/dryml/dryml_support_controller.rb
69
+ - lib/dryml/extensions/action_controller/dryml_methods.rb
81
70
  - lib/dryml/helper.rb
82
71
  - lib/dryml/parser.rb
83
72
  - lib/dryml/parser/attribute.rb
@@ -89,17 +78,19 @@ files:
89
78
  - lib/dryml/parser/text.rb
90
79
  - lib/dryml/parser/tree_parser.rb
91
80
  - lib/dryml/part_context.rb
81
+ - lib/dryml/railtie.rb
82
+ - lib/dryml/railtie/page_tag_resolver.rb
83
+ - lib/dryml/railtie/template_handler.rb
92
84
  - lib/dryml/scoped_variables.rb
93
85
  - lib/dryml/static_tags
94
86
  - lib/dryml/tag_parameters.rb
95
87
  - lib/dryml/taglib.rb
96
88
  - lib/dryml/template.rb
97
89
  - lib/dryml/template_environment.rb
98
- - lib/dryml/template_handler.rb
99
90
  - taglibs/core.dryml
100
91
  - test/dryml.rdoctest
101
92
  has_rdoc: true
102
- homepage: http://hobocentral.net/
93
+ homepage: http://hobocentral.net
103
94
  licenses: []
104
95
 
105
96
  post_install_message:
@@ -112,25 +103,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
112
103
  requirements:
113
104
  - - ">="
114
105
  - !ruby/object:Gem::Version
115
- hash: 3
116
- segments:
117
- - 0
118
106
  version: "0"
119
107
  required_rubygems_version: !ruby/object:Gem::Requirement
120
108
  none: false
121
109
  requirements:
122
110
  - - ">="
123
111
  - !ruby/object:Gem::Version
124
- hash: 3
125
- segments:
126
- - 0
127
- version: "0"
112
+ version: 1.3.6
128
113
  requirements: []
129
114
 
130
115
  rubyforge_project: hobo
131
- rubygems_version: 1.4.2
116
+ rubygems_version: 1.5.0
132
117
  signing_key:
133
118
  specification_version: 3
134
- summary: The web app builder for Rails
119
+ summary: The Don't Repeat Yourself Markup Language
135
120
  test_files: []
136
121
 
@@ -1,13 +0,0 @@
1
- class Dryml::DrymlSupportController < ActionController::Base
2
-
3
- def edit_source
4
- dryml_editor = ENV['DRYML_EDITOR']
5
- if dryml_editor
6
- file = File.join(RAILS_ROOT, params[:file])
7
- command = dryml_editor.sub(":file", file).sub(":line", params[:line])
8
- system(command)
9
- end
10
- render :nothing => true
11
- end
12
-
13
- end
@@ -1,187 +0,0 @@
1
- module Dryml
2
-
3
- class TemplateHandler < ActionView::TemplateHandler
4
-
5
- def compile(*args)
6
- # Ignore - we handle compilation ourselves
7
- end
8
-
9
- # Pre Rails 2.2
10
- def render(template)
11
- renderer = Dryml.page_renderer_for_template(@view, template.locals.keys, template)
12
- this = @view.instance_variable_set("@this", @view.controller.send(:dryml_context) || template.locals[:this])
13
- s = renderer.render_page(this, template.locals)
14
- # Important to strip whitespace, or the browser hangs around for ages (FF2)
15
- s.strip
16
- end
17
-
18
- def render_for_rails22(template, view, local_assigns)
19
- renderer = Dryml.page_renderer_for_template(view, local_assigns.keys, template)
20
- this = view.controller.send(:dryml_context) || local_assigns[:this]
21
- @view._?.instance_variable_set("@this", this)
22
- s = renderer.render_page(this, local_assigns)
23
-
24
- # Important to strip whitespace, or the browser hangs around for ages (FF2)
25
- s.strip
26
- end
27
-
28
- end
29
-
30
- end
31
-
32
- module ActionController
33
-
34
- class Base
35
-
36
- def dryml_context
37
- @this
38
- end
39
-
40
- def dryml_fallback_tag(tag_name)
41
- @dryml_fallback_tag = tag_name
42
- end
43
-
44
-
45
- def call_dryml_tag(tag, options={})
46
- @template.send(:_evaluate_assigns_and_ivars)
47
-
48
- # TODO: Figure out what this bit is all about :-)
49
- if options[:with]
50
- @this = options[:with] unless options[:field]
51
- else
52
- options[:with] = dryml_context
53
- end
54
-
55
- Dryml.render_tag(@template, tag, options)
56
- end
57
-
58
-
59
- # TODO: This is namespace polution, should be called render_dryml_tag
60
- def render_tag(tag, attributes={}, options={})
61
- text = call_dryml_tag(tag, attributes)
62
- text && render({:text => text, :layout => false }.merge(options))
63
- end
64
-
65
- # DRYML fallback tags -- monkey patch this method to attempt to render a tag if there's no template
66
- def render_for_file_with_dryml(template, status = nil, layout = nil, locals = {})
67
- # in rails 2.2, "template" is actually "template_path"
68
-
69
- # if we're passed a MissingTemplateWrapper, see if there's a
70
- # dryml tag that will render the page
71
- if template.respond_to? :original_template_path
72
- # this is the Rails 2.3 path
73
- tag_name = @dryml_fallback_tag || "#{File.basename(template.original_template_path).dasherize}-page"
74
-
75
- text = call_dryml_tag(tag_name)
76
- if text
77
- return render_for_text(text, status)
78
- else
79
- template.raise_wrapped_exception
80
- end
81
- else
82
- begin
83
- result = render_for_file_without_dryml(template, status, layout, locals)
84
- rescue ActionView::MissingTemplate => ex
85
- # this is the Rails 2.2 path
86
- tag_name = @dryml_fallback_tag || "#{File.basename(template).dasherize}-page"
87
-
88
- text = call_dryml_tag(tag_name)
89
- if text
90
- return render_for_text(text, status)
91
- else
92
- raise ex
93
- end
94
- end
95
- end
96
- end
97
- alias_method_chain :render_for_file, :dryml
98
-
99
- end
100
- end
101
-
102
- class ActionView::Template
103
-
104
- def render_with_dryml(view, local_assigns = {})
105
- if handler == Dryml::TemplateHandler
106
- render_dryml(view, local_assigns)
107
- else
108
- render_without_dryml(view, local_assigns)
109
- end
110
- end
111
- alias_method_chain :render, :dryml
112
-
113
- # We've had to copy a bunch of logic from Renderable#render, because we need to prevent Rails
114
- # from trying to compile our template. DRYML templates are each compiled as a class, not just a method,
115
- # so the support for compiling templates that Rails provides is innadequate.
116
- def render_dryml(view, local_assigns = {})
117
- if view.instance_variable_defined?(:@_render_stack)
118
- # Rails 2.2
119
- stack = view.instance_variable_get(:@_render_stack)
120
- stack.push(self)
121
-
122
- # This is only used for TestResponse to set rendered_template
123
- unless is_a?(ActionView::InlineTemplate) || view.instance_variable_get(:@_first_render)
124
- view.instance_variable_set(:@_first_render, self)
125
- end
126
-
127
- view.send(:_evaluate_assigns_and_ivars)
128
- view.send(:_set_controller_content_type, mime_type) if respond_to?(:mime_type)
129
-
130
- result = Dryml::TemplateHandler.new.render_for_rails22(self, view, local_assigns)
131
-
132
- stack.pop
133
- result
134
- else
135
- # Rails 2.3
136
- compile(local_assigns)
137
-
138
- view.with_template self do
139
- view.send(:_evaluate_assigns_and_ivars)
140
- view.send(:_set_controller_content_type, mime_type) if respond_to?(:mime_type)
141
-
142
- Dryml::TemplateHandler.new.render_for_rails22(self, view, local_assigns)
143
- end
144
- end
145
- end
146
-
147
- end
148
-
149
- # this is only used in Rails 2.3
150
- class MissingTemplateWrapper
151
- attr_reader :original_template_path
152
-
153
- def initialize(exception, path)
154
- @exception = exception
155
- @original_template_path = path
156
- end
157
-
158
- def method_missing(*args)
159
- raise @exception
160
- end
161
-
162
- def render
163
- raise @exception
164
- end
165
- end
166
-
167
-
168
- module ActionView
169
- class PathSet < Array
170
- # this is only used by Rails 2.3
171
- def find_template_with_dryml(original_template_path, format = nil, html_fallback = true)
172
- begin
173
- find_template_without_dryml(original_template_path, format, html_fallback)
174
- rescue ActionView::MissingTemplate => ex
175
- # instead of throwing the exception right away, hand back a
176
- # time bomb instead. It'll blow if mishandled...
177
- return MissingTemplateWrapper.new(ex, original_template_path)
178
- end
179
- end
180
-
181
- if method_defined? "find_template"
182
- # only rails 2.3 has this function
183
- alias_method_chain :find_template, :dryml
184
- end
185
- end
186
- end
187
-