dryml 1.3.0.RC2 → 1.3.0.RC3

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.3.0.RC2
1
+ 1.3.0.RC3
@@ -58,10 +58,49 @@ module Dryml
58
58
  end
59
59
 
60
60
 
61
+ class Erubis < ::Erubis::Eruby
62
+ def add_preamble(src)
63
+
64
+ end
65
+
66
+ def add_text(src, text)
67
+ return if text.empty?
68
+ src << "self.output_buffer.safe_concat('" << escape_text(text) << "');"
69
+ end
70
+
71
+ BLOCK_EXPR = /\s+(do|\{)(\s*\|[^|]*\|)?\s*\Z/
72
+
73
+ def add_expr_literal(src, code)
74
+ if code =~ BLOCK_EXPR
75
+ src << 'self.output_buffer.append= ' << code << ";\nself.output_buffer;"
76
+ else
77
+ src << 'self.output_buffer.append= (' << code << ");\nself.output_buffer;"
78
+ end
79
+ end
80
+
81
+ def add_stmt(src, code)
82
+ # skip fallback code - it utterly destroys DRYML-generated ERB
83
+ super
84
+ end
85
+
86
+ def add_expr_escaped(src, code)
87
+ if code =~ BLOCK_EXPR
88
+ src << "self.output_buffer.safe_append= " << code << ";\nself.output_buffer;"
89
+ else
90
+ src << "self.output_buffer.safe_concat((" << code << ").to_s);"
91
+ end
92
+ end
93
+
94
+ def add_postamble(src)
95
+ # NOTE: we can't just add a 'self.output_buffer' here because this parser
96
+ # is used to compile taglibs which don't HAVE one
97
+ end
98
+ end
99
+
61
100
  def erb_process(erb_src)
62
101
  trim_mode = ActionView::TemplateHandlers::ERB.erb_trim_mode
63
- erb = ERB.new(erb_src, nil, trim_mode, "output_buffer")
64
- res = erb.src.split(';')[1..-2].join(';')
102
+ erb = Erubis.new(erb_src, :trim_mode => trim_mode)
103
+ res = erb.src
65
104
  if res.respond_to? :force_encoding
66
105
  res.force_encoding(erb_src.encoding)
67
106
  end
@@ -121,7 +121,7 @@
121
121
  def restore_locals(locals)
122
122
  locals.map do |l|
123
123
  if l.is_a?(TypedId)
124
- Hobo::Model.find_by_typed_id(this_id)
124
+ Hobo::Model.find_by_typed_id(l)
125
125
  else
126
126
  l
127
127
  end
@@ -251,7 +251,11 @@ module Dryml
251
251
  _tag_context(attributes) do
252
252
  attributes.delete :with
253
253
  attributes.delete :field
254
- call_polymorphic_tag('#{name}', attributes, parameters) { #{name}__base(attributes.except, parameters) }
254
+ if for_klass = parse_for_type(attributes)
255
+ call_polymorphic_tag('#{name}', for_klass, attributes, parameters) { #{name}__base(attributes.except, parameters) }
256
+ else
257
+ call_polymorphic_tag('#{name}', attributes, parameters) { #{name}__base(attributes.except, parameters) }
258
+ end
255
259
  end
256
260
  end
257
261
  )
@@ -722,14 +726,14 @@ module Dryml
722
726
  def append_parameter_tag_hash_item(name, el, metadata_name)
723
727
  ":#{ruby_name name} => proc { [{}, { :default => proc { |#{param_content_local_name(name)}| new_context { %>" +
724
728
  param_content_element(name) + children_to_erb(el) +
725
- "<% } } } ] }"
729
+ "<% ; output_buffer } } } ] }"
726
730
  end
727
731
 
728
732
 
729
733
  def prepend_parameter_tag_hash_item(name, el, metadata_name)
730
734
  ":#{ruby_name name} => proc { [{}, { :default => proc { |#{param_content_local_name(name)}| new_context { %>" +
731
735
  children_to_erb(el) + param_content_element(name) +
732
- "<% } } } ] }"
736
+ "<% ; output_buffer } } } ] }"
733
737
  end
734
738
 
735
739
 
@@ -737,7 +741,7 @@ module Dryml
737
741
  content = children_to_erb(el)
738
742
  content = wrap_source_with_metadata(content, "param", containing_param_name,
739
743
  element_line_num(el)) if containing_param_name
740
- "proc { |#{param_content_local_name(el.dryml_name)}| new_context { %>#{content}<% } #{tag_newlines(el)}}"
744
+ "proc { |#{param_content_local_name(el.dryml_name)}| new_context { %>#{content}<% ; output_buffer } #{tag_newlines(el)}}"
741
745
  end
742
746
 
743
747
 
@@ -785,7 +789,7 @@ module Dryml
785
789
  def replace_parameter_proc(el, metadata_name, content=nil)
786
790
  content ||= wrap_replace_parameter(el, metadata_name)
787
791
  param_name = el.dryml_name.sub(/^(before|after|append|prepend)-/, "")
788
- "proc { |#{param_restore_local_name(param_name)}| new_context { %>#{content}<% } #{tag_newlines(el)}}"
792
+ "proc { |#{param_restore_local_name(param_name)}| new_context { %>#{content}<% ; output_buffer } #{tag_newlines(el)}}"
789
793
  end
790
794
 
791
795
 
@@ -813,7 +817,7 @@ module Dryml
813
817
  items = attributes.map do |n,v|
814
818
  dryml_exception("invalid attribute name '#{n}' (remember to use '-' rather than '_')", el) unless n =~ DRYML_NAME_RX
815
819
 
816
- next if n.in?(SPECIAL_ATTRIBUTES) || n =~ /^without-/
820
+ next if n.in?(SPECIAL_ATTRIBUTES-['for-type']) || n =~ /^without-/
817
821
  next if el.attributes['part'] && n == 'id' # The id is rendered on the <div class="part-wrapper"> instead
818
822
 
819
823
  ":#{ruby_name n} => #{attribute_to_ruby(v)}"
@@ -188,6 +188,20 @@ module Dryml
188
188
  end
189
189
  end
190
190
 
191
+ def parse_for_type(attributes)
192
+ t = attributes[:for_type]
193
+ if t.nil?
194
+ nil
195
+ elsif t.is_a?(Class)
196
+ t
197
+ elsif t =~ /^[A-Z]/
198
+ t.constantize
199
+ elsif t =~ /^[a-z]/ && defined?(HoboFields.to_class)
200
+ HoboFields.to_class(t)
201
+ else
202
+ nil
203
+ end
204
+ end
191
205
 
192
206
  def call_polymorphic_tag(name, *args)
193
207
  name = name.to_s.gsub('-', '_')
@@ -246,7 +260,8 @@ module Dryml
246
260
  @_form_field_path, @_form_field_paths_by_object ]
247
261
  @_this_type = nil
248
262
  res = nil
249
- @view.with_output_buffer { res = yield }
263
+ outer_res = @view.with_output_buffer { res = yield }
264
+ Rails.logger.error("new_context: #{caller.first}") if !outer_res.blank? && outer_res.to_s != res.to_s
250
265
  @_this, @_this_parent, @_this_field, @_this_type, @_form_field_path, @_form_field_paths_by_object = ctx
251
266
  res.to_s
252
267
  end
data/lib/dryml.rb CHANGED
@@ -9,6 +9,7 @@ require 'action_pack'
9
9
  require 'openssl'
10
10
 
11
11
  ActiveSupport::Dependencies.autoload_paths |= [File.dirname(__FILE__)]
12
+ ActiveSupport::Dependencies.autoload_once_paths |= [File.dirname(__FILE__)]
12
13
 
13
14
  # The Don't Repeat Yourself Markup Language
14
15
  module Dryml
@@ -65,9 +66,10 @@ module Dryml
65
66
  end
66
67
 
67
68
  def call_render(view, local_assigns, identifier)
68
- renderer = page_renderer(view, identifier, local_assigns.keys)
69
69
  this = view.controller.send(:dryml_context) || local_assigns[:this]
70
70
  view.instance_variable_set("@this", this)
71
+ # do this last, as TemplateEnvironment copies instance variables in initalize
72
+ renderer = page_renderer(view, identifier, local_assigns.keys)
71
73
  if identifier =~ /#{ID_SEPARATOR}/
72
74
  tag_name = identifier.split(ID_SEPARATOR).last
73
75
  renderer.render_tag(tag_name, {:with => this} )
data/taglibs/core.dryml CHANGED
@@ -71,10 +71,10 @@ For example, you might want to wrap an `<img>` tag in an `<a>` tag but only unde
71
71
 
72
72
  ### Usage
73
73
 
74
- <if test="&current_user.administrtator?">Logged in as administrator</if>
74
+ <if test="&current_user.administrator?">Logged in as administrator</if>
75
75
  <else>Logged in as normal user</else>
76
-
77
- **IMPORTANT NOTE**: `<if>` tests for non-blank vs. blank (as defined by ActiveSuport), not true vs. false.
76
+
77
+ **IMPORTANT NOTE**: `<if>` tests for non-blank vs. blank (as defined by ActiveSupport), not true vs. false.
78
78
 
79
79
  If you do not give the `test` attribute, uses the current context instead. This allows a nice trick like this:
80
80
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: dryml
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: 6
5
- version: 1.3.0.RC2
5
+ version: 1.3.0.RC3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Tom Locke
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-08-15 00:00:00 -04:00
13
+ date: 2011-10-25 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -32,7 +32,7 @@ dependencies:
32
32
  requirements:
33
33
  - - "="
34
34
  - !ruby/object:Gem::Version
35
- version: 1.3.0.RC2
35
+ version: 1.3.0.RC3
36
36
  type: :runtime
37
37
  version_requirements: *id002
38
38
  - !ruby/object:Gem::Dependency
@@ -114,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
114
  requirements: []
115
115
 
116
116
  rubyforge_project: hobo
117
- rubygems_version: 1.5.0
117
+ rubygems_version: 1.6.2
118
118
  signing_key:
119
119
  specification_version: 3
120
120
  summary: The Don't Repeat Yourself Markup Language