dryml 1.4.0.pre8 → 2.0.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.4.0.pre8
1
+ 2.0.0.pre1
data/dryml.gemspec CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
11
11
  s.summary = "The Don't Repeat Yourself Markup Language"
12
12
  s.description = "The Don't Repeat Yourself Markup Language"
13
13
 
14
- s.add_runtime_dependency('actionpack', ["~> 3.1.0"])
14
+ s.add_runtime_dependency('actionpack', ["~> 3.2.0"])
15
15
  s.add_runtime_dependency('hobo_support', ["= #{version}"])
16
16
  s.add_development_dependency('rubydoctest', [">= 1.1.3"])
17
17
  s.add_development_dependency('cucumber', '~> 1.1.0')
@@ -100,7 +100,7 @@ module Dryml
100
100
  end
101
101
 
102
102
  def erb_process(erb_src)
103
- trim_mode = ActionView::TemplateHandlers::ERB.erb_trim_mode
103
+ trim_mode = ActionView::Template::Handlers::ERB.erb_trim_mode
104
104
  erb = Erubis.new(erb_src, :trim_mode => trim_mode)
105
105
  res = erb.src
106
106
  if res.respond_to? :force_encoding
@@ -174,18 +174,6 @@ require 'fileutils'
174
174
  end
175
175
 
176
176
 
177
- def linkable?(*args)
178
- options = args.extract_options!
179
- options[:subsite] = subsite
180
- klass, action = if args.length == 1
181
- [model, args.first]
182
- else
183
- args
184
- end
185
- Hobo::Routes.linkable?(klass, action, options)
186
- end
187
-
188
-
189
177
  def sortable_collection?(collection, model=self.model)
190
178
  # There's no perfect way to detect for this, given that acts_as_list
191
179
  # does not provide any metadata to reflect on, but if the :order
@@ -56,7 +56,9 @@
56
56
  def marshal(session)
57
57
  context = [@part_name, @this_id, @locals]
58
58
  context << form_field_path if form_field_path
59
- data = Base64.encode64(Marshal.dump(context)).strip
59
+ # http://stackoverflow.com/questions/2620975/strange-n-in-base64-encoded-string-in-ruby
60
+ # data = Base64.encode64(Marshal.dump(context)).strip
61
+ data = Base64.strict_encode64(Marshal.dump(context)).strip
60
62
  digest = generate_digest(data, session)
61
63
  "#{data}--#{digest}"
62
64
  end
@@ -65,7 +67,6 @@
65
67
  # Unmarshal part context to a hash and verify its integrity.
66
68
  def unmarshal(client_store, page_this, session)
67
69
  data, digest = CGI.unescape(client_store).strip.split('--')
68
-
69
70
  raise TamperedWithPartContext unless digest == generate_digest(data, session)
70
71
 
71
72
  context = Marshal.load(Base64.decode64(data))
@@ -14,6 +14,8 @@ 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
+
17
19
  SPECIAL_ATTRIBUTES = %w(param merge merge-params merge-attrs
18
20
  for-type
19
21
  if unless repeat
@@ -397,9 +399,38 @@ module Dryml
397
399
 
398
400
  "#{start} " +
399
401
  # reproduce any line breaks in the start-tag so that line numbers are preserved
400
- tag_newlines(el) + "%>" + children_to_erb(el) + "<% output_buffer; end"
402
+ tag_newlines(el) + "%>" +
403
+ wrap_tag_method_body_with_metadata(children_to_erb(el)) +
404
+ "<% output_buffer; end"
405
+ end
406
+
407
+ # this function is now basically just a hook for DrymlFireMarker
408
+ def wrap_source_with_metadata(content, kind, name, *args)
409
+ content
410
+ end
411
+
412
+ def wrap_tag_method_body_with_metadata(content)
413
+ name = @def_element.attributes['tag']
414
+ for_ = @def_element.attributes['for']
415
+ name += " for #{for_}" if for_
416
+ wrap_source_with_metadata(content, "def", name, element_line_num(@def_element))
401
417
  end
402
418
 
419
+
420
+ def wrap_tag_call_with_metadata(el, content)
421
+ name = el.expanded_name
422
+ param = el.attributes['param']
423
+
424
+ if param == "&true"
425
+ name += " param"
426
+ elsif param
427
+ name += " param='#{param}'"
428
+ end
429
+
430
+ wrap_source_with_metadata(content, "call", name, element_line_num(el))
431
+ end
432
+
433
+
403
434
  def param_content_local_name(name)
404
435
  "_#{ruby_name name}__default_content"
405
436
  end
@@ -574,7 +605,8 @@ module Dryml
574
605
  end
575
606
 
576
607
  call = apply_control_attributes(call, el)
577
- maybe_make_part_call(el, "<% concat(#{call}) %>")
608
+ call = maybe_make_part_call(el, "<% concat(#{call}) %>")
609
+ wrap_tag_call_with_metadata(el, call)
578
610
  end
579
611
 
580
612
 
@@ -588,6 +620,8 @@ module Dryml
588
620
  def parameter_tags_hash(el, containing_tag_name=nil)
589
621
  call_type = nil
590
622
 
623
+ metadata_name = containing_tag_name || el.expanded_name
624
+
591
625
  param_items = el.map do |node|
592
626
  case node
593
627
  when REXML::Text
@@ -612,7 +646,7 @@ module Dryml
612
646
  end
613
647
 
614
648
  if is_parameter_tag
615
- parameter_tag_hash_item(e) + ", "
649
+ parameter_tag_hash_item(e, metadata_name) + ", "
616
650
  end
617
651
  end
618
652
  end.join
@@ -648,52 +682,52 @@ module Dryml
648
682
  end
649
683
 
650
684
 
651
- def parameter_tag_hash_item(el)
685
+ def parameter_tag_hash_item(el, metadata_name)
652
686
  name = el.name.dup
653
687
  if name.sub!(/^before-/, "")
654
- before_parameter_tag_hash_item(name, el)
688
+ before_parameter_tag_hash_item(name, el, metadata_name)
655
689
  elsif name.sub!(/^after-/, "")
656
- after_parameter_tag_hash_item(name, el)
690
+ after_parameter_tag_hash_item(name, el, metadata_name)
657
691
  elsif name.sub!(/^prepend-/, "")
658
- prepend_parameter_tag_hash_item(name, el)
692
+ prepend_parameter_tag_hash_item(name, el, metadata_name)
659
693
  elsif name.sub!(/^append-/, "")
660
- append_parameter_tag_hash_item(name, el)
694
+ append_parameter_tag_hash_item(name, el, metadata_name)
661
695
  else
662
696
  hash_key = ruby_name name
663
697
  hash_key += "_replacement" if el.attribute("replace")
664
698
  if (param_name = get_param_name(el))
665
- ":#{hash_key} => merge_tag_parameter(#{param_proc(el)}, all_parameters[:#{param_name}])"
699
+ ":#{hash_key} => merge_tag_parameter(#{param_proc(el, metadata_name)}, all_parameters[:#{param_name}])"
666
700
  else
667
- ":#{hash_key} => #{param_proc(el)}"
701
+ ":#{hash_key} => #{param_proc(el, metadata_name)}"
668
702
  end
669
703
  end
670
704
  end
671
705
 
672
706
 
673
- def before_parameter_tag_hash_item(name, el)
707
+ def before_parameter_tag_hash_item(name, el, metadata_name)
674
708
  param_name = get_param_name(el)
675
709
  dryml_exception("param declaration not allowed on 'before' parameters", el) if param_name
676
710
  content = children_to_erb(el) + "<% concat(#{param_restore_local_name(name)}.call({}, {})) %>"
677
- ":#{ruby_name name}_replacement => #{replace_parameter_proc(el, content)}"
711
+ ":#{ruby_name name}_replacement => #{replace_parameter_proc(el, metadata_name, content)}"
678
712
  end
679
713
 
680
714
 
681
- def after_parameter_tag_hash_item(name, el)
715
+ def after_parameter_tag_hash_item(name, el, metadata_name)
682
716
  param_name = get_param_name(el)
683
717
  dryml_exception("param declaration not allowed on 'after' parameters", el) if param_name
684
718
  content = "<% concat(#{param_restore_local_name(name)}.call({}, {})) %>" + children_to_erb(el)
685
- ":#{ruby_name name}_replacement => #{replace_parameter_proc(el, content)}"
719
+ ":#{ruby_name name}_replacement => #{replace_parameter_proc(el, metadata_name, content)}"
686
720
  end
687
721
 
688
722
 
689
- def append_parameter_tag_hash_item(name, el)
723
+ def append_parameter_tag_hash_item(name, el, metadata_name)
690
724
  ":#{ruby_name name} => proc { [{}, { :default => proc { |#{param_content_local_name(name)}| new_context { %>" +
691
725
  param_content_element(name) + children_to_erb(el) +
692
726
  "<% ; output_buffer } } } ] }"
693
727
  end
694
728
 
695
729
 
696
- def prepend_parameter_tag_hash_item(name, el)
730
+ def prepend_parameter_tag_hash_item(name, el, metadata_name)
697
731
  ":#{ruby_name name} => proc { [{}, { :default => proc { |#{param_content_local_name(name)}| new_context { %>" +
698
732
  children_to_erb(el) + param_content_element(name) +
699
733
  "<% ; output_buffer } } } ] }"
@@ -702,6 +736,8 @@ module Dryml
702
736
 
703
737
  def default_param_proc(el, containing_param_name=nil)
704
738
  content = children_to_erb(el)
739
+ content = wrap_source_with_metadata(content, "param", containing_param_name,
740
+ element_line_num(el)) if containing_param_name
705
741
  "proc { |#{param_content_local_name(el.dryml_name)}| new_context { %>#{content}<% ; output_buffer } #{tag_newlines(el)}}"
706
742
  end
707
743
 
@@ -711,14 +747,21 @@ module Dryml
711
747
  end
712
748
 
713
749
 
714
- def param_proc(el)
750
+ def wrap_replace_parameter(el, name)
751
+ wrap_source_with_metadata(children_to_erb(el), "replace", name, element_line_num(el))
752
+ end
753
+
754
+
755
+ def param_proc(el, metadata_name_suffix)
756
+ metadata_name = "#{el.name} < #{metadata_name_suffix}"
757
+
715
758
  nl = tag_newlines(el)
716
759
 
717
760
  if (repl = el.attribute("replace"))
718
761
  dryml_exception("replace attribute must not have a value", el) if repl.has_rhs?
719
762
  dryml_exception("replace parameters must not have attributes", el) if el.attributes.length > 1
720
763
 
721
- replace_parameter_proc(el, children_to_erb(el))
764
+ replace_parameter_proc(el, metadata_name, children_to_erb(el))
722
765
  else
723
766
  attributes = el.attributes.dup
724
767
  # Providing one of 'with' or 'field' but not the other should cancel out the other
@@ -734,13 +777,14 @@ module Dryml
734
777
  end
735
778
  end.compact
736
779
 
737
- nested_parameters_hash = parameter_tags_hash(el)
780
+ nested_parameters_hash = parameter_tags_hash(el, metadata_name)
738
781
  "proc { [{#{attribute_items * ', '}}, #{nested_parameters_hash}] #{nl}}"
739
782
  end
740
783
  end
741
784
 
742
785
 
743
- def replace_parameter_proc(el, content=nil)
786
+ def replace_parameter_proc(el, metadata_name, content=nil)
787
+ content ||= wrap_replace_parameter(el, metadata_name)
744
788
  param_name = el.dryml_name.sub(/^(before|after|append|prepend)-/, "")
745
789
  "proc { |#{param_restore_local_name(param_name)}| new_context { %>#{content}<% ; output_buffer } #{tag_newlines(el)}}"
746
790
  end
@@ -160,7 +160,7 @@ module Dryml
160
160
  end
161
161
  end
162
162
 
163
- id = if (typed_id = object.try.typed_id)
163
+ id = if (!object.is_a?(ActiveRecord::Relation) && typed_id = object.try.typed_id)
164
164
  typed_id
165
165
  elsif object == @this
166
166
  "this"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dryml
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0.pre8
4
+ version: 2.0.0.pre1
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-01 00:00:00.000000000 Z
12
+ date: 2012-09-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: actionpack
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 3.1.0
21
+ version: 3.2.0
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: 3.1.0
29
+ version: 3.2.0
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: hobo_support
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -34,7 +34,7 @@ dependencies:
34
34
  requirements:
35
35
  - - '='
36
36
  - !ruby/object:Gem::Version
37
- version: 1.4.0.pre8
37
+ version: 2.0.0.pre1
38
38
  type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
@@ -42,7 +42,7 @@ dependencies:
42
42
  requirements:
43
43
  - - '='
44
44
  - !ruby/object:Gem::Version
45
- version: 1.4.0.pre8
45
+ version: 2.0.0.pre1
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: rubydoctest
48
48
  requirement: !ruby/object:Gem::Requirement