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 CHANGED
@@ -10,6 +10,7 @@ GEM
10
10
  rake
11
11
  rdoc
12
12
  json (1.7.6)
13
+ nokogiri (1.5.6)
13
14
  rake (10.0.3)
14
15
  rdoc (3.12)
15
16
  json (~> 1.4)
@@ -29,5 +30,6 @@ DEPENDENCIES
29
30
  bundler
30
31
  erubis
31
32
  jeweler (~> 1.8.4)
33
+ nokogiri
32
34
  rdoc (~> 3.12)
33
35
  rspec (~> 2.8.0)
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
- return @@templates[template_name].result({:params => params}).strip
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
@@ -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.1
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.23
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