liquidizer 0.4.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/liquidizer/liquid_template.rb +7 -5
- data/lib/liquidizer.rb +3 -2
- data/liquidizer.gemspec +4 -1
- data/test/fixtures/path_one/template_one.liquid +1 -0
- data/test/fixtures/path_two/template_one.liquid +1 -0
- data/test/fixtures/path_two/template_two.liquid +1 -0
- data/test/liquid_template_test.rb +16 -0
- data/test/test_helper.rb +1 -1
- metadata +6 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.5.0
|
@@ -10,13 +10,15 @@ module Liquidizer
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def find_default_by_name(name)
|
13
|
-
|
13
|
+
Liquidizer.template_paths.each do |path|
|
14
|
+
file_name = File.join(path, name) + '.liquid'
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
nil
|
16
|
+
if File.exist?(file_name)
|
17
|
+
return new(:name => name, :content => File.read(file_name))
|
18
|
+
end
|
19
19
|
end
|
20
|
+
|
21
|
+
nil
|
20
22
|
end
|
21
23
|
end
|
22
24
|
end
|
data/lib/liquidizer.rb
CHANGED
@@ -4,7 +4,8 @@ require 'liquidizer/liquid_template'
|
|
4
4
|
|
5
5
|
module Liquidizer
|
6
6
|
# The path the default liquid templates are stored.
|
7
|
-
mattr_accessor :
|
7
|
+
mattr_accessor :template_paths
|
8
|
+
self.template_paths = []
|
8
9
|
|
9
10
|
# Module for drops. When instance variable is passed to a template, it's wrapped with a drop.
|
10
11
|
# This is a module the drops are looked up. If nil, the drops are looked up in the global
|
@@ -12,6 +13,6 @@ module Liquidizer
|
|
12
13
|
mattr_accessor :drop_module
|
13
14
|
|
14
15
|
if defined?(Rails)
|
15
|
-
self.
|
16
|
+
self.template_paths << "#{Rails.root}/db/liquid_templates"
|
16
17
|
end
|
17
18
|
end
|
data/liquidizer.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{liquidizer}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.5.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Adam Cig\303\241nek"]
|
@@ -35,6 +35,9 @@ Gem::Specification.new do |s|
|
|
35
35
|
"test/fixtures/comments/_stuff.html.erb",
|
36
36
|
"test/fixtures/comments/index.html.erb",
|
37
37
|
"test/fixtures/layouts/layout.html.erb",
|
38
|
+
"test/fixtures/path_one/template_one.liquid",
|
39
|
+
"test/fixtures/path_two/template_one.liquid",
|
40
|
+
"test/fixtures/path_two/template_two.liquid",
|
38
41
|
"test/fixtures/posts/index.liquid",
|
39
42
|
"test/fixtures/posts/show.html.erb",
|
40
43
|
"test/fixtures/ratings/edit.html.erb",
|
@@ -0,0 +1 @@
|
|
1
|
+
Default template one in path one
|
@@ -0,0 +1 @@
|
|
1
|
+
Default template one in path two
|
@@ -0,0 +1 @@
|
|
1
|
+
Default template two in path two
|
@@ -3,6 +3,11 @@ require File.dirname(__FILE__) + '/test_helper'
|
|
3
3
|
class LiquidTemplateTest < ActiveSupport::TestCase
|
4
4
|
def setup
|
5
5
|
LiquidTemplate.delete_all
|
6
|
+
@old_template_paths = Liquidizer.template_paths
|
7
|
+
end
|
8
|
+
|
9
|
+
def teardown
|
10
|
+
Liquidizer.template_paths = @old_template_paths
|
6
11
|
end
|
7
12
|
|
8
13
|
test 'find_by_name finds template by name if it exists' do
|
@@ -19,6 +24,17 @@ class LiquidTemplateTest < ActiveSupport::TestCase
|
|
19
24
|
assert_equal expected_content, found.content
|
20
25
|
end
|
21
26
|
|
27
|
+
test 'find_by_name searches template in all template paths' do
|
28
|
+
Liquidizer.template_paths = [File.dirname(__FILE__) + '/fixtures/path_one',
|
29
|
+
File.dirname(__FILE__) + '/fixtures/path_two']
|
30
|
+
|
31
|
+
expected_one = File.read(File.dirname(__FILE__) + '/fixtures/path_one/template_one.liquid')
|
32
|
+
expected_two = File.read(File.dirname(__FILE__) + '/fixtures/path_two/template_two.liquid')
|
33
|
+
|
34
|
+
assert_equal expected_one, LiquidTemplate.find_by_name('template_one').content
|
35
|
+
assert_equal expected_two, LiquidTemplate.find_by_name('template_two').content
|
36
|
+
end
|
37
|
+
|
22
38
|
test 'find_by_name returns nil if not even default template exists' do
|
23
39
|
assert_nil LiquidTemplate.find_by_name('ninjas!')
|
24
40
|
end
|
data/test/test_helper.rb
CHANGED
@@ -10,7 +10,7 @@ $: << File.dirname(__FILE__) + '/../app/models'
|
|
10
10
|
require 'liquidizer'
|
11
11
|
require 'liquid_template'
|
12
12
|
|
13
|
-
Liquidizer.
|
13
|
+
Liquidizer.template_paths = [File.dirname(__FILE__) + '/fixtures']
|
14
14
|
|
15
15
|
# Establish a temporary sqlite3 db for testing.
|
16
16
|
ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 5
|
8
|
+
- 0
|
9
|
+
version: 0.5.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- "Adam Cig\xC3\xA1nek"
|
@@ -60,6 +60,9 @@ files:
|
|
60
60
|
- test/fixtures/comments/_stuff.html.erb
|
61
61
|
- test/fixtures/comments/index.html.erb
|
62
62
|
- test/fixtures/layouts/layout.html.erb
|
63
|
+
- test/fixtures/path_one/template_one.liquid
|
64
|
+
- test/fixtures/path_two/template_one.liquid
|
65
|
+
- test/fixtures/path_two/template_two.liquid
|
63
66
|
- test/fixtures/posts/index.liquid
|
64
67
|
- test/fixtures/posts/show.html.erb
|
65
68
|
- test/fixtures/ratings/edit.html.erb
|