ahc 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +2 -0
- data/lib/ahc.rb +10 -2
- data/spec/ahc_spec.rb +6 -0
- data/test_template/template.erb +1 -1
- metadata +2 -2
data/Gemfile.lock
CHANGED
data/lib/ahc.rb
CHANGED
@@ -3,15 +3,19 @@ require 'ahcx_template_handler'
|
|
3
3
|
|
4
4
|
class Ahc
|
5
5
|
|
6
|
-
def self.render(template_name, params)
|
6
|
+
def self.render(template_name, params, css_map = {})
|
7
7
|
if @@templates[template_name]
|
8
|
-
|
8
|
+
css = lambda {|css_class|
|
9
|
+
@@css_map[css_class] || css_class
|
10
|
+
}
|
11
|
+
return @@templates[template_name].result({:params => params, :css => css}).strip
|
9
12
|
end
|
10
13
|
return ''
|
11
14
|
end
|
12
15
|
|
13
16
|
def self.read_templates(paths)
|
14
17
|
@@templates = {}
|
18
|
+
@@css_map ||= {}
|
15
19
|
paths.each do |path|
|
16
20
|
if File.directory?(path)
|
17
21
|
Dir.glob(path+"/**/*.css") do |item|
|
@@ -26,6 +30,10 @@ class Ahc
|
|
26
30
|
end
|
27
31
|
end
|
28
32
|
|
33
|
+
def self.set_css_map(css_map)
|
34
|
+
@@css_map = css_map
|
35
|
+
end
|
36
|
+
|
29
37
|
def self.css_provides(stylesheet_path)
|
30
38
|
provides = []
|
31
39
|
File.readlines(stylesheet_path).each do |line|
|
data/spec/ahc_spec.rb
CHANGED
@@ -16,4 +16,10 @@ describe "Ahc" do
|
|
16
16
|
Ahc.render('test.Template', {"content" => "<div>Content</div>"}).should == "<div class='test'><div>Content</div></div>"
|
17
17
|
end
|
18
18
|
|
19
|
+
it "should be able to use css maps" do
|
20
|
+
Ahc.read_templates(['test_template'])
|
21
|
+
Ahc.set_css_map({"test" => "a"})
|
22
|
+
Ahc.render('test.Template', {"content" => "<div>Content</div>"}).should == "<div class='a'><div>Content</div></div>"
|
23
|
+
end
|
24
|
+
|
19
25
|
end
|
data/test_template/template.erb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
<div class='test'><%= params['content']%></div>
|
1
|
+
<div class='<%= css['test']%>'><%= params['content']%></div>
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ahc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -134,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
134
134
|
version: '0'
|
135
135
|
requirements: []
|
136
136
|
rubyforge_project:
|
137
|
-
rubygems_version: 1.8.
|
137
|
+
rubygems_version: 1.8.24
|
138
138
|
signing_key:
|
139
139
|
specification_version: 3
|
140
140
|
summary: Gem for using ahc components in rails application
|