Remarkably 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/remarkably.rb +43 -70
- data/lib/remarkably/engines/css.rb +47 -0
- data/lib/remarkably/engines/css/helpers.rb +7 -0
- data/lib/remarkably/engines/html.rb +24 -0
- data/lib/remarkably/engines/xml.rb +33 -0
- metadata +10 -3
data/lib/remarkably.rb
CHANGED
@@ -1,89 +1,62 @@
|
|
1
1
|
module Remarkably
|
2
|
-
def method_missing(sym, *args, &block)
|
3
|
-
hash = args.last.is_a?(Hash) ? args.pop : {}
|
4
|
-
tag!(sym, args, hash, &block)
|
5
|
-
end
|
6
2
|
|
7
|
-
|
8
|
-
tag_attributes =
|
9
|
-
attributes.inject([]){|s,(k,v)| s << %{#{k.to_s.downcase}="#{v}"} }
|
3
|
+
module Base
|
10
4
|
|
11
|
-
|
5
|
+
class Engine
|
6
|
+
def initialize *args, &block
|
7
|
+
clear!
|
8
|
+
self.instance_eval( &block ) if block_given?
|
9
|
+
end
|
12
10
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
11
|
+
def missing_method(sym, context, *args, &block)
|
12
|
+
@context = context
|
13
|
+
hash = args.last.is_a?(Hash) ? args.pop : {}
|
14
|
+
if methods.index( sym.to_s )
|
15
|
+
self.send( sym, args, hash, &block )
|
16
|
+
else
|
17
|
+
method!(sym, args, hash, &block)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def method_missing(sym, *args, &block)
|
22
|
+
missing_method( sym, self, *args, &block )
|
23
|
+
end
|
24
|
+
|
25
|
+
def clear!
|
26
|
+
@output = ''
|
27
|
+
end
|
28
|
+
|
29
|
+
def method! sym, args, hash, &block
|
30
|
+
end
|
31
|
+
|
32
|
+
def to_s
|
33
|
+
result = @output
|
34
|
+
clear!
|
35
|
+
result
|
20
36
|
end
|
21
|
-
@remarkably << "#{inline.join}</#{tag}>"
|
22
|
-
else
|
23
|
-
@remarkably << "/>"
|
24
|
-
end
|
25
|
-
end
|
26
37
|
|
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
38
|
end
|
34
|
-
@remarkably_method = :css
|
35
|
-
end
|
36
39
|
|
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
40
|
end
|
47
41
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
@
|
52
|
-
@
|
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(' ')};"
|
42
|
+
module Common
|
43
|
+
|
44
|
+
def method_missing(sym, *args, &block)
|
45
|
+
@remarkably_engine ||= eval("Engines::#{Engines::constants[0]}.new")
|
46
|
+
@remarkably_engine.send( :missing_method, sym, self, *args, &block )
|
60
47
|
end
|
61
|
-
end
|
62
48
|
|
63
|
-
|
64
|
-
|
65
|
-
inline = [inline] if inline.class != Array
|
66
|
-
@remarkably ||= ''
|
67
|
-
@remarkably_method ||= :xml
|
68
|
-
|
69
|
-
case @remarkably_method
|
70
|
-
when :xml then tag_xml!( tag, inline, attributes, &block )
|
71
|
-
when :css then tag_css!( tag, inline, attributes, &block )
|
72
|
-
when :css_inner then tag_css_inner!( tag, inline, attributes, &block )
|
73
|
-
else raise "Unknown remarkably method type '#{@remarkably_method}'"
|
49
|
+
def remarkably_engine= engine
|
50
|
+
@remarkably_engine = engine
|
74
51
|
end
|
75
52
|
|
76
|
-
|
77
|
-
|
53
|
+
def remarkably_engine
|
54
|
+
@remarkably_engine
|
55
|
+
end
|
78
56
|
|
79
|
-
def text content
|
80
|
-
@remarkably << content
|
81
|
-
self
|
82
57
|
end
|
83
58
|
|
84
|
-
|
85
|
-
result = @remarkably
|
86
|
-
@remarkably = nil
|
87
|
-
result
|
59
|
+
module Engines
|
88
60
|
end
|
61
|
+
|
89
62
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require "#{File::dirname(__FILE__)}/../../remarkably"
|
2
|
+
|
3
|
+
module Remarkably
|
4
|
+
module Engines
|
5
|
+
class CSS < Base::Engine
|
6
|
+
def method! sym, args, hash, &block
|
7
|
+
sym = sym.to_s.downcase
|
8
|
+
|
9
|
+
if block_given?
|
10
|
+
current_prefix = @css_prefix
|
11
|
+
@css_prefix = (@css_prefix+" #{sym}#{args.map{|a|a.to_s}.join}").strip
|
12
|
+
@css_depth+=1
|
13
|
+
@css_prefix_rendered=false
|
14
|
+
block.call
|
15
|
+
@css_depth-=1
|
16
|
+
@css_prefix = current_prefix
|
17
|
+
else
|
18
|
+
unless @css_prefix_rendered
|
19
|
+
unless @css_first_use
|
20
|
+
@output.chop!
|
21
|
+
@output << "}"
|
22
|
+
end
|
23
|
+
@output << "\n#{@css_prefix} {"
|
24
|
+
@css_prefix_rendered = true
|
25
|
+
@css_first_use = false
|
26
|
+
end
|
27
|
+
@output << "#{sym.gsub('_','-')}:#{args.map{|a|a.to_s}.join(' ')};"
|
28
|
+
end
|
29
|
+
self
|
30
|
+
end
|
31
|
+
|
32
|
+
def to_s
|
33
|
+
"#{super.chop}}".strip+"\n"
|
34
|
+
end
|
35
|
+
|
36
|
+
def clear!
|
37
|
+
super
|
38
|
+
@css_prefix=''
|
39
|
+
@css_depth=0
|
40
|
+
@css_prefix_rendered=false
|
41
|
+
@css_first_use=true
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "#{File::dirname(__FILE__)}/../../remarkably"
|
2
|
+
require "#{File::dirname(__FILE__)}/xml"
|
3
|
+
require "#{File::dirname(__FILE__)}/css"
|
4
|
+
|
5
|
+
module Remarkably
|
6
|
+
module Engines
|
7
|
+
class HTML < XML
|
8
|
+
def initialize
|
9
|
+
super
|
10
|
+
@css_engine = Engines::CSS.new
|
11
|
+
end
|
12
|
+
def style args, hash, &block
|
13
|
+
if block_given?
|
14
|
+
@css_engine.clear!
|
15
|
+
@context.remarkably_engine = @css_engine
|
16
|
+
block.call
|
17
|
+
@context.remarkably_engine = self
|
18
|
+
args = ["\n#{@css_engine}"]+args
|
19
|
+
end
|
20
|
+
method!( :style, args, hash )
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "#{File::dirname(__FILE__)}/../../remarkably"
|
2
|
+
|
3
|
+
module Remarkably
|
4
|
+
module Engines
|
5
|
+
class XML < Base::Engine
|
6
|
+
|
7
|
+
def method! sym, args, hash, &block
|
8
|
+
sym = sym.to_s.downcase
|
9
|
+
|
10
|
+
tag_attributes =
|
11
|
+
hash.inject([]){|s,(k,v)| s << %{#{k.to_s.downcase}="#{v}"} }
|
12
|
+
|
13
|
+
@output << ["<#{sym}", tag_attributes].flatten.grep(/\S/).join(' ')
|
14
|
+
|
15
|
+
if block_given? or not args.empty?
|
16
|
+
@output << ">"
|
17
|
+
block.call if block_given?
|
18
|
+
@output << "#{args.join}</#{sym}>"
|
19
|
+
else
|
20
|
+
@output << "/>"
|
21
|
+
end
|
22
|
+
|
23
|
+
self
|
24
|
+
end
|
25
|
+
|
26
|
+
def text args, hash, &block
|
27
|
+
@output << args.join
|
28
|
+
self
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.
|
2
|
+
rubygems_version: 0.9.3
|
3
3
|
specification_version: 1
|
4
4
|
name: Remarkably
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2007-05-
|
6
|
+
version: 0.5.0
|
7
|
+
date: 2007-05-24 00:00:00 +02:00
|
8
8
|
summary: Remarkably is a very tiny Markaby-like XML builder
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -29,7 +29,14 @@ post_install_message:
|
|
29
29
|
authors:
|
30
30
|
- Clive Crous
|
31
31
|
files:
|
32
|
+
- lib/remarkably
|
32
33
|
- lib/remarkably.rb
|
34
|
+
- lib/remarkably/engines
|
35
|
+
- lib/remarkably/engines/css
|
36
|
+
- lib/remarkably/engines/xml.rb
|
37
|
+
- lib/remarkably/engines/html.rb
|
38
|
+
- lib/remarkably/engines/css.rb
|
39
|
+
- lib/remarkably/engines/css/helpers.rb
|
33
40
|
test_files: []
|
34
41
|
|
35
42
|
rdoc_options: []
|