dryml 1.3.3 → 1.4.0.pre2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/Gemfile +6 -0
  2. data/README +2 -0
  3. data/Rakefile +2 -1
  4. data/VERSION +1 -1
  5. data/cucumber.yml +9 -0
  6. data/dryml.gemspec +4 -2
  7. data/features/cookbook/01_simple_page_templates.feature +44 -0
  8. data/features/cookbook/02_defining_simple_tags.feature +375 -0
  9. data/features/cookbook/03_implicit_context.feature +229 -0
  10. data/features/cookbook/04_tag_attributes.feature +120 -0
  11. data/features/cookbook/05_repeated_and_optional_content.feature +241 -0
  12. data/features/cookbook/06_pseudo_parameters.feature +191 -0
  13. data/features/cookbook/07_nested_parameters.feature +147 -0
  14. data/features/cookbook/08_customizing_tags.feature +307 -0
  15. data/features/cookbook/09_aliasing_tags.feature +50 -0
  16. data/features/cookbook/10_polymorphic_tags.feature +168 -0
  17. data/features/cookbook/11_wrapping_content.feature +57 -0
  18. data/features/cookbook/12_local_and_scoped_variables.feature +102 -0
  19. data/features/doctest_examples.feature +187 -0
  20. data/features/merge_params.feature +36 -0
  21. data/features/replace_parameters.feature +21 -0
  22. data/features/static_tags.feature +91 -0
  23. data/features/step_definitions/contexts.rb +25 -0
  24. data/features/step_definitions/dom_comparison.rb +10 -0
  25. data/features/step_definitions/rendering.rb +21 -0
  26. data/features/support/env.rb +32 -0
  27. data/features/support/models/author.rb +18 -0
  28. data/features/support/models/blog_post.rb +37 -0
  29. data/features/support/models/discussion.rb +15 -0
  30. data/features/support/models/post.rb +12 -0
  31. data/features/support/strip_formatter.rb +14 -0
  32. data/lib/dryml/dryml_builder.rb +4 -14
  33. data/lib/dryml/dryml_doc.rb +6 -1
  34. data/lib/dryml/helper.rb +17 -1
  35. data/lib/dryml/part_context.rb +12 -15
  36. data/lib/dryml/railtie/template_handler.rb +1 -3
  37. data/lib/dryml/railtie.rb +1 -0
  38. data/lib/dryml/taglib.rb +24 -30
  39. data/lib/dryml/template.rb +32 -86
  40. data/lib/dryml/template_environment.rb +40 -17
  41. data/lib/dryml.rb +22 -11
  42. data/taglibs/core.dryml +18 -12
  43. data/taglibs/dryml.dryml +3 -0
  44. metadata +97 -56
@@ -14,8 +14,6 @@ module Dryml
14
14
 
15
15
  CODE_ATTRIBUTE_CHAR = "&"
16
16
 
17
- NO_METADATA_TAGS = %w(doctype if else unless repeat do with name type-name)
18
-
19
17
  SPECIAL_ATTRIBUTES = %w(param merge merge-params merge-attrs
20
18
  for-type
21
19
  if unless repeat
@@ -53,7 +51,7 @@ module Dryml
53
51
 
54
52
  unless @template_path.blank?
55
53
  p = Pathname.new template_path
56
- p = Pathname.new(Rails.root) + p unless p.absolute? || !Object.const_defined?(:Rails)
54
+ p = Pathname.new(Rails.root) + p unless p.absolute? || !Object.const_defined?(:Rails) || Rails.root.nil?
57
55
  mtime = p.mtime rescue Time.now
58
56
 
59
57
  if !@builder.ready?(mtime)
@@ -155,8 +153,10 @@ module Dryml
155
153
  tag_newlines(el)
156
154
 
157
155
  when "set-theme"
156
+ require_toplevel(el)
158
157
  require_attribute(el, "name", /^#{DRYML_NAME}$/)
159
- @builder.add_build_instruction(:set_theme, :name => el.attributes['name'])
158
+ Rails.logger.debug "set-theme has been deprecated. Please use <include gem='hobo_#{el.attributes['name']}'/> instead."
159
+ @builder.add_build_instruction(:include, :gem => "hobo_#{el.attributes['name']}")
160
160
 
161
161
  # return nothing - set_theme has no presence in the erb source
162
162
  tag_newlines(el)
@@ -397,44 +397,9 @@ module Dryml
397
397
 
398
398
  "#{start} " +
399
399
  # reproduce any line breaks in the start-tag so that line numbers are preserved
400
- tag_newlines(el) + "%>" +
401
- wrap_tag_method_body_with_metadata(children_to_erb(el)) +
402
- "<% output_buffer; end"
403
- end
404
-
405
- def wrap_source_with_metadata(content, kind, name, *args)
406
- if (!include_source_metadata) || name.in?(NO_METADATA_TAGS)
407
- content
408
- else
409
- metadata = [kind, name] + args + [@template_path]
410
- "<% safe_concat(%(<!--[DRYML|#{metadata * '|'}[-->)) %>" +
411
- content +
412
- "<% safe_concat(%(<!--]DRYML]-->)) %>"
413
- end
414
- end
415
-
416
- def wrap_tag_method_body_with_metadata(content)
417
- name = @def_element.attributes['tag']
418
- for_ = @def_element.attributes['for']
419
- name += " for #{for_}" if for_
420
- wrap_source_with_metadata(content, "def", name, element_line_num(@def_element))
400
+ tag_newlines(el) + "%>" + children_to_erb(el) + "<% output_buffer; end"
421
401
  end
422
402
 
423
-
424
- def wrap_tag_call_with_metadata(el, content)
425
- name = el.expanded_name
426
- param = el.attributes['param']
427
-
428
- if param == "&true"
429
- name += " param"
430
- elsif param
431
- name += " param='#{param}'"
432
- end
433
-
434
- wrap_source_with_metadata(content, "call", name, element_line_num(el))
435
- end
436
-
437
-
438
403
  def param_content_local_name(name)
439
404
  "_#{ruby_name name}__default_content"
440
405
  end
@@ -465,9 +430,11 @@ module Dryml
465
430
 
466
431
  def simple_part_element(el, content)
467
432
  part_name = el.attributes['part']
468
- dom_id = el.attributes['id'] || part_name
469
433
  part_name = ruby_name(part_name)
470
434
  part_locals = el.attributes["part-locals"]
435
+ dom_id = el.attributes['id']
436
+
437
+ raise 'id should have been added elsewhere' if dom_id.nil?
471
438
 
472
439
  part_src = "<% def #{part_name}_part(#{part_locals._?.gsub('@', '')}) #{tag_newlines(el)}; new_context do %>" +
473
440
  content +
@@ -564,7 +531,6 @@ module Dryml
564
531
  end
565
532
  end
566
533
 
567
-
568
534
  def tag_call(el)
569
535
  name = call_name(el)
570
536
  param_name = get_param_name(el)
@@ -608,8 +574,7 @@ module Dryml
608
574
  end
609
575
 
610
576
  call = apply_control_attributes(call, el)
611
- call = maybe_make_part_call(el, "<% concat(#{call}) %>")
612
- wrap_tag_call_with_metadata(el, call)
577
+ maybe_make_part_call(el, "<% concat(#{call}) %>")
613
578
  end
614
579
 
615
580
 
@@ -623,8 +588,6 @@ module Dryml
623
588
  def parameter_tags_hash(el, containing_tag_name=nil)
624
589
  call_type = nil
625
590
 
626
- metadata_name = containing_tag_name || el.expanded_name
627
-
628
591
  param_items = el.map do |node|
629
592
  case node
630
593
  when REXML::Text
@@ -649,7 +612,7 @@ module Dryml
649
612
  end
650
613
 
651
614
  if is_parameter_tag
652
- parameter_tag_hash_item(e, metadata_name) + ", "
615
+ parameter_tag_hash_item(e) + ", "
653
616
  end
654
617
  end
655
618
  end.join
@@ -669,7 +632,7 @@ module Dryml
669
632
  elsif is_code_attribute?(merge_params)
670
633
  merge_params[1..-1]
671
634
  else
672
- merge_param_names = merge_params.split(/\s*,\s*/).*.gsub("-", "_")
635
+ merge_param_names = merge_params.split(/\s*,\s*/).*.gsub("-", "_").*.to_sym
673
636
  "all_parameters & #{merge_param_names.inspect}"
674
637
  end
675
638
  "merge_parameter_hashes({#{param_items}}, (#{extra_params}) || {})"
@@ -685,52 +648,52 @@ module Dryml
685
648
  end
686
649
 
687
650
 
688
- def parameter_tag_hash_item(el, metadata_name)
651
+ def parameter_tag_hash_item(el)
689
652
  name = el.name.dup
690
653
  if name.sub!(/^before-/, "")
691
- before_parameter_tag_hash_item(name, el, metadata_name)
654
+ before_parameter_tag_hash_item(name, el)
692
655
  elsif name.sub!(/^after-/, "")
693
- after_parameter_tag_hash_item(name, el, metadata_name)
656
+ after_parameter_tag_hash_item(name, el)
694
657
  elsif name.sub!(/^prepend-/, "")
695
- prepend_parameter_tag_hash_item(name, el, metadata_name)
658
+ prepend_parameter_tag_hash_item(name, el)
696
659
  elsif name.sub!(/^append-/, "")
697
- append_parameter_tag_hash_item(name, el, metadata_name)
660
+ append_parameter_tag_hash_item(name, el)
698
661
  else
699
662
  hash_key = ruby_name name
700
663
  hash_key += "_replacement" if el.attribute("replace")
701
664
  if (param_name = get_param_name(el))
702
- ":#{hash_key} => merge_tag_parameter(#{param_proc(el, metadata_name)}, all_parameters[:#{param_name}])"
665
+ ":#{hash_key} => merge_tag_parameter(#{param_proc(el)}, all_parameters[:#{param_name}])"
703
666
  else
704
- ":#{hash_key} => #{param_proc(el, metadata_name)}"
667
+ ":#{hash_key} => #{param_proc(el)}"
705
668
  end
706
669
  end
707
670
  end
708
671
 
709
672
 
710
- def before_parameter_tag_hash_item(name, el, metadata_name)
673
+ def before_parameter_tag_hash_item(name, el)
711
674
  param_name = get_param_name(el)
712
675
  dryml_exception("param declaration not allowed on 'before' parameters", el) if param_name
713
676
  content = children_to_erb(el) + "<% concat(#{param_restore_local_name(name)}.call({}, {})) %>"
714
- ":#{ruby_name name}_replacement => #{replace_parameter_proc(el, metadata_name, content)}"
677
+ ":#{ruby_name name}_replacement => #{replace_parameter_proc(el, content)}"
715
678
  end
716
679
 
717
680
 
718
- def after_parameter_tag_hash_item(name, el, metadata_name)
681
+ def after_parameter_tag_hash_item(name, el)
719
682
  param_name = get_param_name(el)
720
683
  dryml_exception("param declaration not allowed on 'after' parameters", el) if param_name
721
684
  content = "<% concat(#{param_restore_local_name(name)}.call({}, {})) %>" + children_to_erb(el)
722
- ":#{ruby_name name}_replacement => #{replace_parameter_proc(el, metadata_name, content)}"
685
+ ":#{ruby_name name}_replacement => #{replace_parameter_proc(el, content)}"
723
686
  end
724
687
 
725
688
 
726
- def append_parameter_tag_hash_item(name, el, metadata_name)
689
+ def append_parameter_tag_hash_item(name, el)
727
690
  ":#{ruby_name name} => proc { [{}, { :default => proc { |#{param_content_local_name(name)}| new_context { %>" +
728
691
  param_content_element(name) + children_to_erb(el) +
729
692
  "<% ; output_buffer } } } ] }"
730
693
  end
731
694
 
732
695
 
733
- def prepend_parameter_tag_hash_item(name, el, metadata_name)
696
+ def prepend_parameter_tag_hash_item(name, el)
734
697
  ":#{ruby_name name} => proc { [{}, { :default => proc { |#{param_content_local_name(name)}| new_context { %>" +
735
698
  children_to_erb(el) + param_content_element(name) +
736
699
  "<% ; output_buffer } } } ] }"
@@ -739,8 +702,6 @@ module Dryml
739
702
 
740
703
  def default_param_proc(el, containing_param_name=nil)
741
704
  content = children_to_erb(el)
742
- content = wrap_source_with_metadata(content, "param", containing_param_name,
743
- element_line_num(el)) if containing_param_name
744
705
  "proc { |#{param_content_local_name(el.dryml_name)}| new_context { %>#{content}<% ; output_buffer } #{tag_newlines(el)}}"
745
706
  end
746
707
 
@@ -750,21 +711,14 @@ module Dryml
750
711
  end
751
712
 
752
713
 
753
- def wrap_replace_parameter(el, name)
754
- wrap_source_with_metadata(children_to_erb(el), "replace", name, element_line_num(el))
755
- end
756
-
757
-
758
- def param_proc(el, metadata_name_suffix)
759
- metadata_name = "#{el.name} < #{metadata_name_suffix}"
760
-
714
+ def param_proc(el)
761
715
  nl = tag_newlines(el)
762
716
 
763
717
  if (repl = el.attribute("replace"))
764
718
  dryml_exception("replace attribute must not have a value", el) if repl.has_rhs?
765
719
  dryml_exception("replace parameters must not have attributes", el) if el.attributes.length > 1
766
720
 
767
- replace_parameter_proc(el, metadata_name)
721
+ replace_parameter_proc(el, children_to_erb(el))
768
722
  else
769
723
  attributes = el.attributes.dup
770
724
  # Providing one of 'with' or 'field' but not the other should cancel out the other
@@ -780,14 +734,13 @@ module Dryml
780
734
  end
781
735
  end.compact
782
736
 
783
- nested_parameters_hash = parameter_tags_hash(el, metadata_name)
737
+ nested_parameters_hash = parameter_tags_hash(el)
784
738
  "proc { [{#{attribute_items * ', '}}, #{nested_parameters_hash}] #{nl}}"
785
739
  end
786
740
  end
787
741
 
788
742
 
789
- def replace_parameter_proc(el, metadata_name, content=nil)
790
- content ||= wrap_replace_parameter(el, metadata_name)
743
+ def replace_parameter_proc(el, content=nil)
791
744
  param_name = el.dryml_name.sub(/^(before|after|append|prepend)-/, "")
792
745
  "proc { |#{param_restore_local_name(param_name)}| new_context { %>#{content}<% ; output_buffer } #{tag_newlines(el)}}"
793
746
  end
@@ -796,7 +749,7 @@ module Dryml
796
749
  def maybe_make_part_call(el, call)
797
750
  part_name = el.attributes['part']
798
751
  if part_name
799
- part_id = el.attributes['id'] || part_name
752
+ part_id=(el.attributes['id'] ||= "\#{create_part_id('#{part_name}', '#{el.attributes['part-locals']}', binding)}")
800
753
 
801
754
  "<% safe_concat(\"<div class='part-wrapper' id='#{attribute_to_ruby(part_id)[1..-2]}'>\") %>" +
802
755
  part_element(el, call) +
@@ -854,17 +807,15 @@ module Dryml
854
807
 
855
808
  def static_tag_to_method_call(el)
856
809
  part = el.attributes["part"]
810
+ if part && !el.attributes["id"]
811
+ el.attributes["id"] = "\#{create_part_id('#{part}', '#{el.attributes['part-locals']}', binding)}"
812
+ end
857
813
  attrs = el.attributes.map do |n, v|
858
814
  next if n.in? SPECIAL_ATTRIBUTES
859
815
  val = restore_erb_scriptlets(v).gsub('"', '\"').gsub(/<%=(.*?)%>/, '#{\1}')
860
816
  %('#{n}' => "#{val}")
861
817
  end.compact
862
818
 
863
- # If there's a part but no id, the id defaults to the part name
864
- if part && !el.attributes["id"]
865
- attrs << ":id => '#{part}'"
866
- end
867
-
868
819
  # Convert the attributes hash to a call to merge_attrs if
869
820
  # there's a merge-attrs attribute
870
821
  attrs = if el.attributes['merge-attrs']
@@ -1029,11 +980,6 @@ module Dryml
1029
980
  "#{name}_#{@gensym_counter}"
1030
981
  end
1031
982
 
1032
- def include_source_metadata
1033
- @include_source_metadata = Rails.env.development? && !ENV['DRYML_EDITOR'].blank? if @include_source_metadata.nil?
1034
- @include_source_metadata
1035
- end
1036
-
1037
983
  end
1038
984
 
1039
985
  end
@@ -23,7 +23,6 @@ module Dryml
23
23
 
24
24
  end
25
25
 
26
- include ActionView::Helpers
27
26
  include Helper ## FIXME remove
28
27
 
29
28
  def initialize(view=nil)
@@ -105,6 +104,10 @@ module Dryml
105
104
  end
106
105
 
107
106
 
107
+ def deunderscore_attributes(attrs)
108
+ HashWithIndifferentAccess[attrs.map{ |attr, value| [attr.to_s.gsub('_', '-'), value]}]
109
+ end
110
+
108
111
  def add_classes!(attributes, *classes)
109
112
  classes = classes.flatten.select{|x|x}
110
113
  current = attributes[:class]
@@ -117,13 +120,28 @@ module Dryml
117
120
  add_classes!(HashWithIndifferentAccess.new(attributes), classes)
118
121
  end
119
122
 
123
+ def add_data_rapid!(attrs, tag, options)
124
+ data_rapid = ActiveSupport::JSON.decode(attrs["data_rapid"] || "{}")
125
+ attrs["data_rapid"] = data_rapid.update(tag => options).to_json
126
+ attrs
127
+ end
128
+
129
+ def add_data_rapid(attrs, tag, options)
130
+ add_data_rapid!(HashWithIndifferentAccess.new(attrs), tag, options)
131
+ end
120
132
 
121
133
  def merge_attrs(attrs, overriding_attrs)
122
- return {}.update(attrs) if overriding_attrs.nil?
134
+ attrs = {}.update(attrs)
135
+ return attrs if overriding_attrs.nil?
123
136
  attrs = attrs.with_indifferent_access unless attrs.is_a?(HashWithIndifferentAccess)
124
137
  classes = overriding_attrs[:class]
125
- attrs = add_classes(attrs, *classes.split) if classes
126
- attrs.update(overriding_attrs - [:class])
138
+ add_classes!(attrs, *classes.split) if classes
139
+ if (data_rapid = overriding_attrs["data_rapid"])
140
+ attrs["data_rapid"]=ActiveSupport::JSON.decode(attrs["data_rapid"] || "{}").
141
+ update(ActiveSupport::JSON.decode(data_rapid)).to_json
142
+ end
143
+
144
+ attrs.update(overriding_attrs - [:class, :data_rapid])
127
145
  end
128
146
 
129
147
 
@@ -229,7 +247,7 @@ module Dryml
229
247
  found = poly_name
230
248
  break
231
249
  else
232
- if call_type == ActiveRecord::Base || call_type == Object
250
+ if call_type == Object
233
251
  found = name
234
252
  break
235
253
  else
@@ -270,7 +288,18 @@ module Dryml
270
288
  def new_object_context(new_this)
271
289
  new_context do
272
290
  if new_this.respond_to?(:origin)
273
- @_this_parent, @_this_field = new_this.origin, new_this.origin_attribute
291
+ refl = (new_this.origin && new_this.origin_attribute.is_a?(Symbol) && new_this.origin.class.respond_to?(:reflections) && new_this.origin.class.reflections[new_this.origin_attribute])
292
+ if refl.nil? || refl.macro==:belongs_to || refl.macro==:has_one
293
+ @_this_parent, @_this_field = new_this.origin, new_this.origin_attribute
294
+ else
295
+ # See bug #989 for more discussion. The commented out
296
+ # section is more 'correct', but it is expensive and since
297
+ # nobody really ran into this before, setting to nil seems
298
+ # more appropriate.
299
+ @_this_parent, @_this_field = nil, nil
300
+ #@_this_parent = new_this.origin.send(new_this.origin_attribute)
301
+ #@_this_field = @_this_parent.index(new_this) || @_this_parent.length
302
+ end
274
303
  else
275
304
  @_this_parent, @_this_field = [nil, nil]
276
305
  end
@@ -542,11 +571,10 @@ module Dryml
542
571
  end
543
572
 
544
573
 
545
- def part_contexts_storage
546
- PartContext.client_side_storage(@_part_contexts, session)
574
+ def part_contexts_storage_uncoded
575
+ PartContext.client_side_storage_uncoded(@_part_contexts, session)
547
576
  end
548
577
 
549
-
550
578
  def render_tag(tag_name, attributes)
551
579
  method_name = tag_name.to_s.gsub('-', '_')
552
580
  if respond_to?(method_name)
@@ -583,15 +611,10 @@ module Dryml
583
611
  attr_string = " #{attrs.sort * ' '}" unless attrs.empty?
584
612
  end
585
613
  content = capture { new_context &block } if block_given?
586
- res = if empty
587
- "<#{name}#{attr_string}#{scope.xmldoctype ? ' /' : ''}>".html_safe
588
- else
589
- "<#{name}#{attr_string}>".html_safe + content + "</#{name}>".html_safe
590
- end
591
- if content.is_a? ActionView::NonConcattingString
592
- concat res
614
+ if empty
615
+ "<#{name}#{attr_string}#{scope.xmldoctype ? ' /' : ''}>".html_safe
593
616
  else
594
- res
617
+ "<#{name}#{attr_string}>".html_safe + content + "</#{name}>".html_safe
595
618
  end
596
619
  end
597
620
 
data/lib/dryml.rb CHANGED
@@ -17,6 +17,7 @@ module Dryml
17
17
  VERSION = File.read(File.expand_path('../../VERSION', __FILE__)).strip
18
18
  @@root = Pathname.new File.expand_path('../..', __FILE__)
19
19
  def self.root; @@root; end
20
+ EDIT_LINK_BASE = "https://github.com/tablatom/hobo_tree_table/edit/master/dryml"
20
21
 
21
22
  class DrymlSyntaxError < RuntimeError; end
22
23
 
@@ -35,7 +36,6 @@ module Dryml
35
36
  ID_SEPARATOR = '; dryml-tag: '
36
37
  APPLICATION_TAGLIB = { :src => "taglibs/application" }
37
38
  CORE_TAGLIB = { :src => "core", :plugin => "dryml" }
38
- DEFAULT_IMPORTS = defined?(ApplicationHelper) ? [ApplicationHelper] : []
39
39
  @cache = {}
40
40
  extend self
41
41
  attr_accessor :last_if
@@ -43,7 +43,7 @@ module Dryml
43
43
  def precompile_taglibs
44
44
  Dir.chdir(Rails.root) do
45
45
  Dir["app/views/taglibs/**/*.dryml"].each do |f|
46
- Taglib.get(:template_dir => File.dirname(f), :src => File.basename(f).remove(".dryml"))
46
+ Taglib.get(:template_dir => File.dirname(f), :src => File.basename(f).remove(".dryml"), :source_template => f)
47
47
  end
48
48
  end
49
49
  end
@@ -78,11 +78,18 @@ module Dryml
78
78
  end
79
79
  end
80
80
 
81
- def page_renderer(view, identifier, local_names=[], controller_path=nil)
81
+ def imports_for_view(view)
82
+ imports = []
83
+ imports << Sprockets::Helpers::RailsHelper if defined?(Sprockets) && defined?(Rails)
84
+ imports << ActionView::Helpers if defined?(ActionView)
85
+ imports + view.controller.class.modules_for_helpers(view.controller.class.all_helpers_from_path(view.controller.class.helpers_path))
86
+ end
87
+
88
+ def page_renderer(view, identifier, local_names=[], controller_path=nil, imports=nil)
82
89
  controller_path ||= view.controller.controller_path
83
90
  if identifier =~ /#{ID_SEPARATOR}/
84
91
  identifier = identifier.split(ID_SEPARATOR).first
85
- @cache[identifier] ||= make_renderer_class("", "", local_names, taglibs_for(controller_path))
92
+ @cache[identifier] ||= make_renderer_class("", "", local_names, taglibs_for(controller_path), imports_for_view(view))
86
93
  @cache[identifier].new(view)
87
94
  else
88
95
  mtime = File.mtime(identifier)
@@ -92,7 +99,8 @@ module Dryml
92
99
  (local_names - renderer_class.compiled_local_names).any? || # any new local names?
93
100
  renderer_class.load_time < mtime) # cache out of date?
94
101
  renderer_class = make_renderer_class(File.read(identifier), identifier,
95
- local_names, taglibs_for(controller_path))
102
+ local_names, taglibs_for(controller_path),
103
+ imports_for_view(view))
96
104
  renderer_class.load_time = mtime
97
105
  @cache[identifier] = renderer_class
98
106
  end
@@ -169,13 +177,15 @@ module Dryml
169
177
  # "core", :plugin => "dryml" } is automatically
170
178
  # added to this list.
171
179
  # @param [ActionView::Base] view an ActionView instance
172
- def render(template_src, locals={}, template_path=nil, included_taglibs=[], view=nil)
180
+ # @param [Array] A list of helper modules to import. For example,
181
+ # [ActionView::Base]
182
+ def render(template_src, locals={}, template_path=nil, included_taglibs=[], view=nil, imports=nil)
173
183
  template_path ||= template_src
174
184
  view ||= ActionView::Base.new(ActionController::Base.view_paths, {})
175
185
  this = locals.delete(:this) || nil
176
186
 
177
187
  renderer_class = Dryml::Template.build_cache[template_path]._?.environment ||
178
- make_renderer_class(template_src, template_path, locals.keys)
188
+ make_renderer_class(template_src, template_path, locals.keys, included_taglibs, imports)
179
189
  renderer_class.new(view).render_page(this, locals)
180
190
  end
181
191
 
@@ -217,15 +227,16 @@ private
217
227
  # "core", :plugin => "dryml" } is automatically
218
228
  # added to this list.
219
229
  #
220
- def make_renderer_class(template_src, template_path, locals=[], taglibs=[])
230
+ def make_renderer_class(template_src, template_path, locals=[], taglibs=[], imports=nil)
221
231
  renderer_class = Class.new(TemplateEnvironment)
222
- compile_renderer_class(renderer_class, template_src, template_path, locals, taglibs)
232
+ compile_renderer_class(renderer_class, template_src, template_path, locals, taglibs, imports)
223
233
  renderer_class
224
234
  end
225
235
 
226
- def compile_renderer_class(renderer_class, template_src, template_path, locals, taglibs=[])
236
+ def compile_renderer_class(renderer_class, template_src, template_path, locals, taglibs=[], imports=nil)
227
237
  template = Dryml::Template.new(template_src, renderer_class, template_path)
228
- DEFAULT_IMPORTS.each {|m| template.import_module(m)}
238
+
239
+ imports.each {|m| template.import_module(m)} if imports
229
240
 
230
241
  # the sum of all the names we've seen so far - eventually we'll be ready for all of 'em
231
242
  all_local_names = renderer_class.compiled_local_names | locals
data/taglibs/core.dryml CHANGED
@@ -5,7 +5,7 @@
5
5
  -->
6
6
  <def tag="call-tag" attrs="tag">
7
7
  <%= Dryml.static_tags.include?(tag) ?
8
- content_tag(tag, parameters.default, attributes) :
8
+ content_tag(tag, parameters.default, deunderscore_attributes(attributes)) :
9
9
  send(tag.gsub('-', '_'), attributes, parameters) %>
10
10
  </def>
11
11
 
@@ -25,7 +25,7 @@ For example, you might want to wrap an `<img>` tag in an `<a>` tag but only unde
25
25
  <% parameter ||= :default %>
26
26
  <%= if when_
27
27
  if Dryml.static_tags.include?(tag)
28
- content_tag(tag, parameters.default, attributes)
28
+ content_tag(tag, parameters.default, deunderscore_attributes(attributes))
29
29
  else
30
30
  send(tag.gsub('-', '_'), attributes, { parameter.to_sym => parameters[:default] })
31
31
  end
@@ -115,32 +115,38 @@ collection is considered blank)
115
115
 
116
116
 
117
117
  <!-- nodoc. Define core HTML tags defined in Rapid so that DRYML can be used without Rapid. -->
118
- <def tag="html"><%=raw "<html#{tag_options(attributes, true)}>" -%><do param="default"/><%= raw "</html>" -%></def>
118
+ <def tag="html"><%=raw "<html#{tag_options(deunderscore_attributes(attributes), true)}>" -%><do param="default"/><%= raw "</html>" -%></def>
119
119
 
120
120
  <!-- nodoc. Define core HTML tags defined in Rapid so that DRYML can be used without Rapid. -->
121
- <def tag="table"><%=raw "<table#{tag_options(attributes, true)}>" -%><do param="default"/><%= raw "</table>" -%></def>
121
+ <def tag="table"><%=raw "<table#{tag_options(deunderscore_attributes(attributes), true)}>" -%><do param="default"/><%= raw "</table>" -%></def>
122
122
 
123
123
  <!-- nodoc. Define core HTML tags defined in Rapid so that DRYML can be used without Rapid. -->
124
- <def tag="a"><%=raw "<a#{tag_options(attributes, true)}>" -%><do param="default"/><%= raw "</a>" -%></def>
124
+ <def tag="a"><%=raw "<a#{tag_options(deunderscore_attributes(attributes), true)}>" -%><do param="default"/><%= raw "</a>" -%></def>
125
125
 
126
126
  <!-- nodoc. Define core HTML tags defined in Rapid so that DRYML can be used without Rapid. -->
127
- <def tag="section"><%=raw "<section#{tag_options(attributes, true)}>" -%><do param="default"/><%= raw "</section>" -%></def>
127
+ <def tag="section"><%=raw "<section#{tag_options(deunderscore_attributes(attributes), true)}>" -%><do param="default"/><%= raw "</section>" -%></def>
128
128
 
129
129
  <!-- nodoc. Define core HTML tags defined in Rapid so that DRYML can be used without Rapid. -->
130
- <def tag="header"><%=raw "<header#{tag_options(attributes, true)}>" -%><do param="default"/><%= raw "</header>" -%></def>
130
+ <def tag="header"><%=raw "<header#{tag_options(deunderscore_attributes(attributes), true)}>" -%><do param="default"/><%= raw "</header>" -%></def>
131
131
 
132
132
  <!-- nodoc. Define core HTML tags defined in Rapid so that DRYML can be used without Rapid. -->
133
- <def tag="footer"><%=raw "<footer#{tag_options(attributes, true)}>" -%><do param="default"/><%= raw "</footer>" -%></def>
133
+ <def tag="footer"><%=raw "<footer#{tag_options(deunderscore_attributes(attributes), true)}>" -%><do param="default"/><%= raw "</footer>" -%></def>
134
134
 
135
135
  <!-- nodoc. Define core HTML tags defined in Rapid so that DRYML can be used without Rapid. -->
136
- <def tag="form"><%=raw "<form#{tag_options(attributes, true)}>" -%><do param="default"/><%= raw "</form>" -%></def>
136
+ <def tag="form"><%=raw "<form#{tag_options(deunderscore_attributes(attributes), true)}>" -%><do param="default"/><%= raw "</form>" -%></def>
137
137
 
138
138
  <!-- nodoc. Define core HTML tags defined in Rapid so that DRYML can be used without Rapid. -->
139
- <def tag="submit"><%=raw "<submit#{tag_options(attributes, true)}>" -%><do param="default"/><%= raw "</submit>" -%></def>
139
+ <def tag="submit"><%=raw "<submit#{tag_options(deunderscore_attributes(attributes), true)}>" -%><do param="default"/><%= raw "</submit>" -%></def>
140
140
 
141
141
  <!-- nodoc. Define core HTML tags defined in Rapid so that DRYML can be used without Rapid. -->
142
- <def tag="input"><%=raw "<input#{tag_options(attributes, true)}>" -%><do param="default"/><%= raw "</input>" -%></def>
142
+ <def tag="input"><%=raw "<input#{tag_options(deunderscore_attributes(attributes), true)}>" -%><do param="default"/><%= raw "</input>" -%></def>
143
143
 
144
144
  <!-- nodoc. Define core HTML tags defined in Rapid so that DRYML can be used without Rapid. -->
145
- <def tag="link"><%=raw "<link#{tag_options(attributes, true)}>" -%><do param="default"/><%= raw "</link>" -%></def>
145
+ <def tag="link"><%=raw "<link#{tag_options(deunderscore_attributes(attributes), true)}>" -%><do param="default"/><%= raw "</link>" -%></def>
146
146
 
147
+ <!-- nodoc. Define core HTML tags defined in Rapid so that DRYML can be used without Rapid. -->
148
+ <def tag="img"><%=raw "<img#{tag_options(attributes, true)} />" -%></def>
149
+
150
+ <!-- nodoc: used to provide documentation for a tag without actually defining the tag -->
151
+ <def tag="fakedef">
152
+ </def>
@@ -0,0 +1,3 @@
1
+ <!-- this file exists so the cookbook can find it. -->
2
+
3
+ <include src="core"/>