Remarkably 0.2.1 → 0.3.0

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 (2) hide show
  1. data/lib/remarkably.rb +68 -19
  2. metadata +2 -2
@@ -1,35 +1,84 @@
1
1
  module Remarkably
2
2
  def method_missing(sym, *args, &block)
3
- hash = if args.size > 0 && args[-1].class == Hash
4
- args.pop
5
- else
6
- Hash.new
7
- end
8
- tag! sym.to_s.downcase, args, hash, &block
9
- end
10
- def tag! tag, inline, attributes, &block
11
- @remarkably = '' if !@remarkably
3
+ hash = args.last.is_a?(Hash) ? args.pop : {}
4
+ tag!(sym.to_s.downcase, args, hash, &block)
5
+ end
6
+
7
+ def tag_xml!( tag, inline, attributes, &block )
12
8
  tag_attributes =
13
- attributes.inject([]) do |result,data_pair|
14
- key,data = data_pair
15
- result << "#{key.to_s.downcase}=\"#{data.to_s}\""
16
- end.join(' ')
17
- @remarkably << "<#{tag}" +
18
- (tag_attributes.size > 0 ? ' ' + tag_attributes : '')
19
- if block_given? or inline.size > 0
9
+ attributes.inject([]){|s,(k,v)| s << %{#{k.to_s.downcase}="#{v}"} }
10
+
11
+ @remarkably << ["<#{tag}", tag_attributes].flatten.grep(/\S/).join(' ')
12
+
13
+ if block_given? or not inline.empty?
20
14
  @remarkably << ">"
21
- result = block.call if block_given?
22
- @remarkably << inline.shift.to_s while inline.size > 0
23
- @remarkably << "</#{tag}>"
15
+ @remarkably_method = :css if @remarkably_method == :xml and tag == "style"
16
+ block.call if block_given?
17
+ if @remarkably_method == :css and tag == "style"
18
+ @remarkably_method = :xml
19
+ @remarkably << "\n"
20
+ end
21
+ @remarkably << "#{inline.join}</#{tag}>"
24
22
  else
25
23
  @remarkably << "/>"
26
24
  end
25
+ end
26
+
27
+ def tag_css!( tag, inline, attributes, &block )
28
+ @remarkably_method = :css_inner
29
+ if block_given?
30
+ @remarkably << "\n "
31
+ tag_css_inner!( tag, inline, attributes, &block )
32
+ @remarkably << "}"
33
+ end
34
+ @remarkably_method = :css
35
+ end
36
+
37
+ def inline_style &block
38
+ current_remarkably = @remarkably
39
+ @remarkably_method = :css_inner
40
+ @remarkably = ''
41
+ block.call if block_given?
42
+ result = @remarkably
43
+ @remarkably_method = :xml
44
+ @remarkably = current_remarkably
45
+ result
46
+ end
47
+
48
+ def tag_css_inner!( tag, inline, attributes, &block )
49
+ if block_given?
50
+ @remarkably.chop!
51
+ @remarkably << "#{tag}#{inline.join}"
52
+ @remarkably << ".#{attributes[:class]}" if attributes.has_key?( :class )
53
+ @remarkably << "##{attributes[:id]}" if attributes.has_key?( :id )
54
+ @remarkably << ":#{attributes[:pseudo]}" if attributes.has_key?( :pseudo )
55
+ @remarkably << " {"
56
+ block.call
57
+ else
58
+ tag.gsub!('_','-')
59
+ @remarkably << "#{tag}:#{inline.join(' ')};"
60
+ end
61
+ end
62
+
63
+ def tag!(tag, inline, attributes, &block)
64
+ @remarkably ||= ''
65
+ @remarkably_method ||= :xml
66
+
67
+ case @remarkably_method
68
+ when :xml then tag_xml!( tag, inline, attributes, &block )
69
+ when :css then tag_css!( tag, inline, attributes, &block )
70
+ when :css_inner then tag_css_inner!( tag, inline, attributes, &block )
71
+ else raise "Unknown remarkably method type '#{@remarkably_method}'"
72
+ end
73
+
27
74
  self
28
75
  end
76
+
29
77
  def text content
30
78
  @remarkably << content
31
79
  self
32
80
  end
81
+
33
82
  def remarkably
34
83
  result = @remarkably
35
84
  @remarkably = nil
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: Remarkably
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.2.1
7
- date: 2007-05-03 00:00:00 +02:00
6
+ version: 0.3.0
7
+ date: 2007-05-15 00:00:00 +02:00
8
8
  summary: Remarkably is a very tiny Markaby-like XML builder
9
9
  require_paths:
10
10
  - lib