active_text 0.0.2 → 0.0.3
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.
- data/README.textile +6 -0
- data/VERSION +1 -1
- data/active_text.gemspec +1 -1
- data/lib/active_text/base.rb +14 -0
- data/spec/active_text_spec.rb +13 -0
- metadata +3 -3
data/README.textile
CHANGED
@@ -54,6 +54,12 @@ $link_color: #555;
|
|
54
54
|
|
55
55
|
You can also mass update: <pre>@at.update_attributes(:bg_image => %Q("http://anotherurl.com/img.jpg"), :link_color => "green")</pre>
|
56
56
|
|
57
|
+
h2. Methods
|
58
|
+
|
59
|
+
Besides calling .attribute, you can ask for all attributes:
|
60
|
+
|
61
|
+
<pre>@at.attributes</pre> returns a hash <pre>{"mbc" => ActiveText::Variable, "mbc2" => ActiveText::Variable}</pre>
|
62
|
+
|
57
63
|
h2. Gotchas
|
58
64
|
|
59
65
|
Right now, only the following metadata will work:
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
data/active_text.gemspec
CHANGED
data/lib/active_text/base.rb
CHANGED
@@ -12,6 +12,8 @@ module ActiveText
|
|
12
12
|
options[:comment] ||= /\/\//
|
13
13
|
options[:context] ||= "(^(?:#{options[:comment]}\s@.*#{options[:eol]}){#{options[:context_lines]}})"
|
14
14
|
@options = options
|
15
|
+
|
16
|
+
scan
|
15
17
|
end
|
16
18
|
|
17
19
|
def update_attributes(args)
|
@@ -29,8 +31,20 @@ module ActiveText
|
|
29
31
|
@text
|
30
32
|
end
|
31
33
|
|
34
|
+
def attributes
|
35
|
+
@variables
|
36
|
+
end
|
37
|
+
|
32
38
|
protected
|
33
39
|
|
40
|
+
# scans though the text and instantiates all the variables in @variables
|
41
|
+
def scan
|
42
|
+
@text.each do |string|
|
43
|
+
string =~ /^\${1}([a-zA-Z0-9_]+):.+;/
|
44
|
+
@variables[$1] = ActiveText::Variable.new($1, context_of($1), @options[:comment]) if $1
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
34
48
|
# Whenever a variable is requested for, it falls into this.
|
35
49
|
def method_missing(method_name)
|
36
50
|
if method_name.to_s =~ /[\w]+/
|
data/spec/active_text_spec.rb
CHANGED
@@ -93,4 +93,17 @@ $mbc: #555;}
|
|
93
93
|
@s.mbc.value.should == "#555"
|
94
94
|
end
|
95
95
|
|
96
|
+
it "should keep a record of what attributes are in it" do
|
97
|
+
@text = %{// @name Masthead Background Image
|
98
|
+
// @kind file
|
99
|
+
// @description Background image.
|
100
|
+
$mbc2: "http://someurl.com/image.jpg";
|
101
|
+
|
102
|
+
// @name Masthead BG Color
|
103
|
+
// @kind color
|
104
|
+
// @description Background color.
|
105
|
+
$mbc: #555;}
|
106
|
+
@at = ActiveText::Base.new(@text)
|
107
|
+
@at.attributes.size.should == 2
|
108
|
+
end
|
96
109
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_text
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ramon Tayag
|