liquify 0.1 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,21 +1,5 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
1
+ pkg/*
2
+ *.gem
3
+ .bundle
14
4
  *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
-
21
- ## PROJECT::SPECIFIC
5
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in liquify.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,96 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ liquify (0.2)
5
+ liquid (>= 2.2.2)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ abstract (1.0.0)
11
+ actionmailer (3.0.3)
12
+ actionpack (= 3.0.3)
13
+ mail (~> 2.2.9)
14
+ actionpack (3.0.3)
15
+ activemodel (= 3.0.3)
16
+ activesupport (= 3.0.3)
17
+ builder (~> 2.1.2)
18
+ erubis (~> 2.6.6)
19
+ i18n (~> 0.4)
20
+ rack (~> 1.2.1)
21
+ rack-mount (~> 0.6.13)
22
+ rack-test (~> 0.5.6)
23
+ tzinfo (~> 0.3.23)
24
+ activemodel (3.0.3)
25
+ activesupport (= 3.0.3)
26
+ builder (~> 2.1.2)
27
+ i18n (~> 0.4)
28
+ activerecord (3.0.3)
29
+ activemodel (= 3.0.3)
30
+ activesupport (= 3.0.3)
31
+ arel (~> 2.0.2)
32
+ tzinfo (~> 0.3.23)
33
+ activeresource (3.0.3)
34
+ activemodel (= 3.0.3)
35
+ activesupport (= 3.0.3)
36
+ activesupport (3.0.3)
37
+ arel (2.0.6)
38
+ builder (2.1.2)
39
+ diff-lcs (1.1.2)
40
+ erubis (2.6.6)
41
+ abstract (>= 1.0.0)
42
+ i18n (0.5.0)
43
+ liquid (2.2.2)
44
+ mail (2.2.13)
45
+ activesupport (>= 2.3.6)
46
+ i18n (>= 0.4.0)
47
+ mime-types (~> 1.16)
48
+ treetop (~> 1.4.8)
49
+ mime-types (1.16)
50
+ polyglot (0.3.1)
51
+ rack (1.2.1)
52
+ rack-mount (0.6.13)
53
+ rack (>= 1.0.0)
54
+ rack-test (0.5.6)
55
+ rack (>= 1.0)
56
+ rails (3.0.3)
57
+ actionmailer (= 3.0.3)
58
+ actionpack (= 3.0.3)
59
+ activerecord (= 3.0.3)
60
+ activeresource (= 3.0.3)
61
+ activesupport (= 3.0.3)
62
+ bundler (~> 1.0)
63
+ railties (= 3.0.3)
64
+ railties (3.0.3)
65
+ actionpack (= 3.0.3)
66
+ activesupport (= 3.0.3)
67
+ rake (>= 0.8.7)
68
+ thor (~> 0.14.4)
69
+ rake (0.8.7)
70
+ rspec (2.3.0)
71
+ rspec-core (~> 2.3.0)
72
+ rspec-expectations (~> 2.3.0)
73
+ rspec-mocks (~> 2.3.0)
74
+ rspec-core (2.3.1)
75
+ rspec-expectations (2.3.0)
76
+ diff-lcs (~> 1.1.2)
77
+ rspec-mocks (2.3.0)
78
+ rspec-rails (2.3.1)
79
+ actionpack (~> 3.0)
80
+ activesupport (~> 3.0)
81
+ railties (~> 3.0)
82
+ rspec (~> 2.3.0)
83
+ thor (0.14.6)
84
+ treetop (1.4.9)
85
+ polyglot (>= 0.3.1)
86
+ tzinfo (0.3.23)
87
+
88
+ PLATFORMS
89
+ ruby
90
+
91
+ DEPENDENCIES
92
+ liquid (>= 2.2.2)
93
+ liquify!
94
+ rails (~> 3.0.1)
95
+ rspec (~> 2.3.0)
96
+ rspec-rails (~> 2.3.0)
data/README.textile ADDED
@@ -0,0 +1,5 @@
1
+ h1. Liquify
2
+
3
+ The Liquify gem is a wrapper to the very popular Liquid templating engine.
4
+ The goal of this project is to make working with Liquid templates, drops, tags, etc.
5
+ as easy as possible.
data/Rakefile CHANGED
@@ -1,49 +1,2 @@
1
- require 'rubygems'
2
- require 'rake'
3
-
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "liquify"
8
- gem.version = "0.1"
9
- gem.summary = %Q{Liquify is a wrapper to Liquid Markup to make it easier to use}
10
- gem.description = gem.summary
11
- gem.email = "dane.harrigan@gmail.com"
12
- gem.homepage = "http://github.com/daneharrigan/liquify"
13
- gem.authors = ["Dane Harrigan"]
14
- gem.add_development_dependency "rspec", ">= 1.3.0"
15
- gem.add_dependency "liquid", "2.1.2"
16
-
17
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
18
- end
19
- Jeweler::GemcutterTasks.new
20
- rescue LoadError
21
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
22
- end
23
-
24
- require 'spec/rake/spectask'
25
- Spec::Rake::SpecTask.new(:spec) do |spec|
26
- spec.libs << 'lib' << 'spec'
27
- spec.spec_files = FileList['spec/**/*_spec.rb']
28
- end
29
-
30
- Spec::Rake::SpecTask.new(:rcov) do |spec|
31
- spec.libs << 'lib' << 'spec'
32
- spec.pattern = 'spec/**/*_spec.rb'
33
- spec.rcov = true
34
- spec.rcov_opts = ['--exclude', 'gem,spec']
35
- end
36
-
37
- task :spec => :check_dependencies
38
-
39
- task :default => :spec
40
-
41
- require 'rake/rdoctask'
42
- Rake::RDocTask.new do |rdoc|
43
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
-
45
- rdoc.rdoc_dir = 'rdoc'
46
- rdoc.title = "liquify #{version}"
47
- rdoc.rdoc_files.include('README*')
48
- rdoc.rdoc_files.include('lib/**/*.rb')
49
- end
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'liquify'
@@ -0,0 +1,12 @@
1
+ module Liquify
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ desc 'Copy Liquify installation files'
5
+ source_root File.expand_path('../templates', __FILE__)
6
+
7
+ def copy_initializers
8
+ copy_file 'liquify.rb', 'config/initializers/liquify.rb'
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ Liquify.setup do |config|
2
+ # A tag is a class that inherits from Liquify::Tag or Liquid::Tag
3
+ # config.register_tag :tag_name, TagClass
4
+
5
+ # A drop is a class that inherits from Liquify::Drop or Liquid::Drop
6
+ # config.register_drop :drop_name, DropClass
7
+
8
+ # A filter is a method within a module. Multiple filters can be registered
9
+ # at once within a single module.
10
+ # config.register_filters FiltersModule
11
+ end
@@ -0,0 +1,5 @@
1
+ module Liquify
2
+ class Drop < Liquid::Drop
3
+ include Liquify::Methods
4
+ end
5
+ end
@@ -0,0 +1,48 @@
1
+ module Liquify
2
+ module Methods
3
+ def self.included(base)
4
+ base.send(:include, Liquify::InstanceMethods)
5
+ base.send(:extend, Liquify::ClassMethods)
6
+ end
7
+ end
8
+
9
+ module ClassMethods
10
+ protected
11
+ def liquify_method(*args)
12
+ liquify_args = instance_variable_get :@liquify_args
13
+ liquify_args ||= {}
14
+
15
+ args.each do |arg|
16
+ key, value = arg, :self
17
+
18
+ if Hash === arg
19
+ arg.each { |k, v| liquify_args[k.to_s] = v }
20
+ else
21
+ liquify_args[key.to_s] = value
22
+ end
23
+ end
24
+ instance_variable_set :@liquify_args, liquify_args
25
+ end
26
+ end
27
+
28
+ module InstanceMethods
29
+ unless method_defined? :to_liquid
30
+ def to_liquid #:nodoc:
31
+ liquify_args = self.class.instance_variable_get(:@liquify_args) || {}
32
+ liquify_output = instance_variable_get(:@liquify_output) || {}
33
+
34
+ if liquify_output.empty?
35
+ liquify_args.each do |key, value|
36
+ if value.respond_to?(:call)
37
+ liquify_output[key] = value.arity.zero? ? value.call : value.call(self)
38
+ else
39
+ liquify_output[key] = self.send(key)
40
+ end
41
+ end
42
+ end
43
+
44
+ liquify_output
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,35 @@
1
+ module Liquify
2
+ class Parameter < Array
3
+ def initialize(markup, context={})
4
+ markup = markup.split(',')
5
+ args = []
6
+ options = {}
7
+
8
+ markup.each do |arg|
9
+ key, value = arg.split(':')
10
+ key = strip_quotes(key.strip)
11
+
12
+ if value
13
+ value = (value =~ /("|')/) ? strip_quotes(value.strip) : context[value.strip]
14
+ options[key] = value
15
+ else
16
+ args << key
17
+ end
18
+ end
19
+ args << options unless options.empty?
20
+
21
+ super(args)
22
+ end
23
+
24
+ unless self.instance_methods.include? :extract_options!
25
+ def extract_options!
26
+ last.is_a?(Hash) ? pop : {}
27
+ end
28
+ end
29
+
30
+ private
31
+ def strip_quotes(value)
32
+ value.strip.gsub(/^('|")|('|")$/,'')
33
+ end
34
+ end
35
+ end
data/lib/liquify/tag.rb CHANGED
@@ -1,20 +1,14 @@
1
- class Liquify
1
+ module Liquify
2
2
  class Tag < Liquid::Tag
3
- def initialize(tag_name, markup, tokens)
4
- @_params = Liquify.parameters(markup)
5
- end
6
-
7
3
  def render(context)
8
- invoke if respond_to? :invoke
9
- end
10
-
11
- private
12
- def parameters
13
- return @_params
14
- end
4
+ return unless respond_to? :invoke
15
5
 
16
- def parameter
17
- parameters.first
6
+ if method(:invoke).arity == 0
7
+ invoke
8
+ else
9
+ params = Liquify::Parameter.new(@markup, context)
10
+ invoke(params)
11
+ end
18
12
  end
19
13
  end
20
- end
14
+ end
@@ -0,0 +1,3 @@
1
+ module Liquify
2
+ VERSION = "0.2"
3
+ end
data/lib/liquify.rb CHANGED
@@ -1,100 +1,81 @@
1
1
  require 'liquid'
2
+ require 'liquify/methods'
3
+ require 'liquify/parameter'
4
+ require 'liquify/drop'
5
+ require 'liquify/tag'
2
6
 
3
- class Liquify
7
+ if defined?(Rails) && Rails.version >= '3'
8
+ require File.expand_path(File.dirname(__FILE__) + '/rails/active_record_hook.rb')
9
+ end
10
+
11
+ module Liquify
12
+ @@tags = {}
4
13
  @@filters = []
5
14
  @@drops = {}
6
- @@tags = {}
7
- @@template_root = nil
8
15
 
9
16
  class << self
10
- def setup(&block)
11
- new.instance_eval(&block)
12
- @@filters.each { |filter| Liquid::Template.register_filter(filter) }
13
- @@tags.each { |tag, klass| Liquid::Template.register_tag(tag, klass) }
17
+ # setup - This method allows you to register tags, drops and filters.
18
+ # to Liquify in one place.
19
+ #
20
+ # Liquify.setup do |config|
21
+ # ...
22
+ # end
23
+ def setup
24
+ yield self
14
25
  end
15
26
 
16
- def render(args)
17
- source = case
18
- when String === args
19
- args
20
- when args[:template]
21
- path = [@@template_root, args[:template]].compact.join('/')
22
- File.read(path) if File.exist? path
23
- end
24
-
25
- Liquid::Template.parse(source).render(@@drops)
27
+ # register_tag - This method is used to make tags available to your
28
+ # Liquid templates. It accepts a symbol for the tag name and the tag class.
29
+ #
30
+ # Liquify.setup do |config|
31
+ # config.register_tag :tag_name, NameTag
32
+ # end
33
+ def register_tag(name, klass)
34
+ @@tags[name] = klass
26
35
  end
27
36
 
28
- def parameters(params)
29
- return if params.nil?
30
- params = params.split(',')
31
- params.map! { |param| param.strip.gsub(/(^('|")|('|")$)/,'') }
37
+ # register_filters - This method is used to make filters available to
38
+ # your Liquid templates. It accepts a module of methods. Each method
39
+ # becomes a Liquid filter.
40
+ #
41
+ # Liquify.setup do |config|
42
+ # config.register_filters CustomFilters
43
+ # end
44
+ def register_filters(mod)
45
+ @@filters << mod
32
46
  end
33
47
 
34
- def parameter(params)
35
- params = parameters(params)
36
- params.first if params
48
+ # register_drop - This method is used to make drops available to
49
+ # your Liquid templates. It accepts a symbol for the drop name and
50
+ # your drop class or a lambda if processing has to be done at time
51
+ # time of rendering the Liquid template.
52
+ #
53
+ # Liquify.setup do |config|
54
+ # config.register_drop :drop_name, NameDrop
55
+ # # with a lamda
56
+ # config.register_drop :special_name, lambda { Foo.first }
57
+ # end
58
+ def register_drop(name, klass)
59
+ @@drops[name] = klass
37
60
  end
38
- end
39
-
40
- # +register_filter+ - This method accepts a module and is used to add
41
- # Liquid filters.
42
- # Liquify.setup do
43
- # register_filter MyFilters
44
- # end
45
- #
46
- # A filter is a method stored in a module. The +MyFilters+ would be
47
- # setup like this:
48
- # module MyFilters
49
- # def bold_text(text)
50
- # "<strong>#{text}</strong>"
51
- # end
52
- # end
53
- #
54
- # The +MyFilters+ methods will be available in any liquid source
55
- # rendered with +Liquify.render+.
56
- #
57
- # Liquify.render("{{ 'my sample' | bold_text }}")
58
- # # or read from a file
59
- # Liquify.render(:template => 'path/to/file.liquid')
60
- # # => <strong>my sample</strong>
61
- def register_filter(mod)
62
- @@filters << mod unless @@filters.include? mod
63
- end
64
61
 
65
- def register_drop(name, klass)
66
- @@drops[name.to_s] ||= klass.new
67
- end
68
-
69
- # +register_tag+ - This method accepts two arguments, a symbol
70
- # of the tag name used within the Liquid source and the custom
71
- # tag class made by you.
72
- #
73
- # Liquify.setup do
74
- # register_tag :include, IncludeDrop
75
- # end
76
- #
77
- # A tag is a class that inherits from the class +Liquid::Tag+
78
- # or +<tt>Liquify::Tag</tt>+.
79
- # setup like this:
80
- # class IncludeTag < Liquify::Tag
81
- # def invoke
82
- # # your impressive ruby code here
83
- # end
84
- # end
85
- #
86
- # The +MyFilters+ methods will be available in any liquid source
87
- # rendered with +Liquify.render+.
88
- #
89
- # Liquify.render("{{ 'my sample' | bold_text }}")
90
- # # or read from a file
91
- # Liquify.render(:template => 'path/to/file.liquid')
92
- # # => <strong>my sample</strong>
93
- def register_tag(name, klass)
94
- @@tags[name.to_s] ||= klass
95
- end
62
+ # invoke = This method handles to rendering of the Liquid template with
63
+ # all of the registered drops, tags and filters. It accepts the Liquid
64
+ # template as a string.
65
+ #
66
+ # template = '{{ drop_name.method }}'
67
+ # Liquify.invoke(template) # => Rendered Liquid template
68
+ def invoke(template)
69
+ args = {}
70
+ @@drops.each { |name, klass| args[name.to_s] = klass.respond_to?(:call) ? klass.call : klass.new }
71
+ @@filters.each { |filter| Liquid::Template.register_filter(filter) }
72
+ @@tags.each { |tag, klass| Liquid::Template.register_tag(tag, klass) }
73
+ Liquid::Template.parse(template).render(args)
74
+ end
96
75
 
97
- def template_root(path)
98
- @@template_root = path
76
+ def render(template)
77
+ warn 'DEPRECATED: render has been replaced with invoke'
78
+ invoke(template)
79
+ end
99
80
  end
100
- end
81
+ end
@@ -0,0 +1,3 @@
1
+ ActiveSupport.on_load(:active_record) do
2
+ include Liquify::Methods
3
+ end
data/liquify.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "liquify/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "liquify"
7
+ s.version = Liquify::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Dane Harrigan"]
10
+ s.email = ["dane.harrigan@gmail.com"]
11
+ s.homepage = ""
12
+ s.summary = %q{A wrapper for Liquid Markup to make it easier to use}
13
+ s.description = s.summary
14
+
15
+ s.rubyforge_project = "liquify"
16
+ s.add_dependency 'liquid', '>= 2.2.2'
17
+ s.add_development_dependency 'rspec', '~> 2.3.0'
18
+
19
+ s.files = `git ls-files`.split("\n")
20
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
22
+ s.require_paths = ["lib"]
23
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'active_record_hook' do
4
+ describe '.liquify_method' do
5
+ it 'responds to liquify_method' do
6
+ Foo.respond_to?(:liquify_method).should == true
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe Liquify::Methods do
4
+ describe '.liquify_method' do
5
+ before(:each) do
6
+ Liquify.setup do |config|
7
+ config.register_drop :bar, BarDrop
8
+ end
9
+ end
10
+
11
+ it 'returns the value of a method on the drop instance' do
12
+ template = '{{ bar.first_name }} {{ bar.last_name }}'
13
+ Liquify.invoke(template).should == 'Foo Bar'
14
+ end
15
+
16
+ it 'returns the output of a labmda with an argument passed' do
17
+ Liquify.invoke('{{ bar.full_name }}').should == 'Foo Bar'
18
+ end
19
+
20
+ it 'returns the output of a labmda without an argument passed' do
21
+ Liquify.invoke('{{ bar.age }}').should == '25'
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+
3
+ describe Liquify::Parameter do
4
+ it 'parses a string into an array' do
5
+ parameters = Liquify::Parameter.new('"a", "b", "c"')
6
+ parameters.should == %W(a b c)
7
+ end
8
+
9
+ it 'parses a string into an array with a hash' do
10
+ parameters = Liquify::Parameter.new('"a", "b", foo: "bar", baz: "cux"')
11
+ parameters.should == ['a', 'b', {'foo' => 'bar', 'baz' => 'cux'}]
12
+ end
13
+
14
+ context 'when a hash is passed in referencing a context value' do
15
+ it 'assigns the context value to the hash entry' do
16
+ parameters = Liquify::Parameter.new('"a", foo: bar', { 'bar' => {:cux => 'qux'} })
17
+ parameters.should == ['a', {'foo' => {:cux => 'qux'} }]
18
+ end
19
+ end
20
+
21
+ describe '#extract_options!' do
22
+ context 'when a hash is available' do
23
+ before(:each) do
24
+ @parameters = Liquify::Parameter.new('"a", "b", foo: "bar", baz: "cux"')
25
+ @options = @parameters.extract_options!
26
+ end
27
+
28
+ it 'returns the hash' do
29
+ @options.should == {'foo' => 'bar', 'baz' => 'cux'}
30
+ end
31
+
32
+ it 'pulls the hash out of the parameters array' do
33
+ @parameters.should == %W(a b)
34
+ end
35
+ end
36
+
37
+ context 'when there is no hash' do
38
+ before(:each) do
39
+ @parameters = Liquify::Parameter.new('"a", "b", "c"')
40
+ @options = @parameters.extract_options!
41
+ end
42
+
43
+ it 'returns an empty hash' do
44
+ @options.should == {}
45
+ end
46
+
47
+ it 'should leave the parameters array untouched' do
48
+ @parameters.should == %W(a b c)
49
+ end
50
+ end
51
+ end
52
+ end
@@ -1,13 +1,31 @@
1
- require File.expand_path(File.dirname(__FILE__)+'/../spec_helper')
1
+ require 'spec_helper'
2
2
 
3
- describe "Liquify::Tag" do
4
- it "should parse parameters" do
5
- tag = Liquify::Tag.new('tag_name',"'param-1', 'param-2'", nil)
6
- tag.send(:parameters).should == %W{param-1 param-2}
3
+ describe Liquify::Tag do
4
+ before(:each) do
5
+ Liquify.setup do |config|
6
+ config.register_tag :foo, FooTag
7
+ config.register_drop :bar, BarDrop
8
+ end
7
9
  end
8
10
 
9
- it "should parse a single parameter" do
10
- tag = Liquify::Tag.new('tag_name',"'param-1'", nil)
11
- tag.send(:parameter).should == 'param-1'
11
+ context 'when a single argument is passed in' do
12
+ it 'returns the argument' do
13
+ template = '{% foo "bar" %}'
14
+ Liquify.invoke(template).should == 'bar'
15
+ end
12
16
  end
13
- end
17
+
18
+ context 'when an argument and a hash is passed in' do
19
+ it 'returns the argument and the hash value' do
20
+ template = '{% foo "bar", bar: "baz" %}'
21
+ Liquify.invoke(template).should == 'bar baz'
22
+ end
23
+ end
24
+
25
+ context 'when an argument is not quoted' do
26
+ it 'returns the context value that matches the name' do
27
+ template = '{% foo "bar", user: bar %}'
28
+ Liquify.invoke(template).should == 'bar Foo'
29
+ end
30
+ end
31
+ end
data/spec/liquify_spec.rb CHANGED
@@ -1,93 +1,55 @@
1
- path = File.expand_path(File.dirname(__FILE__))
2
- require "#{path}/spec_helper"
1
+ require 'spec_helper'
3
2
 
4
- describe "Liquify" do
5
- it "should have a setup method" do
6
- Liquify.respond_to?(:setup).should == true
7
- end
8
-
9
- it "should return an array of parameters" do
10
- # extra white space is intentional
11
- output = Liquify.parameters("'param-1', 'param-2', 'param-3' ")
12
- output.should == %W{param-1 param-2 param-3}
13
- end
14
-
15
- it "should return a single parameter" do
16
- # extra white space is intentional
17
- Liquify.parameter("'param-1' ").should == 'param-1'
18
- end
3
+ describe Liquify do
4
+ describe '.register_tag' do
5
+ it 'adds a tag to liquify' do
6
+ Liquify.setup do |config|
7
+ config.register_tag :foo, FooTag
8
+ end
19
9
 
20
- context "when rendering a liquid template" do
21
- it "should render the source" do
22
- Liquify.render("{{ 'sample text' }}").should =~ /^sample text$/
10
+ Liquify.class_variable_get(:@@tags).include?(:foo).should == true
23
11
  end
12
+ end
24
13
 
25
- it "should render the template" do
26
- Liquify.render(:template => "#{path}/liquid/templates/sample.liquid").should =~ /^sample text$/
27
- end
14
+ describe '.register_filters' do
15
+ it 'adds a set of filters to liquify' do
16
+ Liquify.setup do |config|
17
+ config.register_filters FooFilters
18
+ end
28
19
 
29
- it "should render nil" do
30
- Liquify.render(:template => "#{path}/does_not_exist.liquid").should be_empty
20
+ Liquify.class_variable_get(:@@filters).include?(FooFilters).should == true
31
21
  end
22
+ end
32
23
 
33
- it "should render the template as a relative path" do
34
- Liquify.setup do
35
- template_root path
24
+ describe '.register_drop' do
25
+ it 'adds a drop to liquify' do
26
+ Liquify.setup do |config|
27
+ config.register_drop :foo, FooDrop
36
28
  end
37
29
 
38
- Liquify.render(:template => 'liquid/templates/sample.liquid')
30
+ Liquify.class_variable_get(:@@drops).include?(:foo).should == true
39
31
  end
40
32
  end
41
33
 
42
- context "when adding a filter" do
43
- before(:all) do
44
- Liquify.setup do
45
- register_filter SpecFilter
46
- end
47
- end
48
-
49
- it "should render bold text" do
50
- output = Liquify.render("{{ 'sample text' | bold_text }}")
51
- output.should =~ /^\<strong\>sample text\<\/strong\>$/
52
- end
53
- end
34
+ describe '.invoke' do
35
+ context 'when a drop is registered as a class' do
36
+ before(:each) do
37
+ foo_drop = mock(FooDrop, :to_liquid => {'first_name' => 'Foo'})
38
+ FooDrop.should_receive(:new).and_return(foo_drop)
39
+ @template = '{{ foo.first_name }}'
54
40
 
55
- context "when adding a drop" do
56
- before(:all) do
57
- Liquify.setup do
58
- register_drop :item, SpecDrop
41
+ Liquify.setup do |config|
42
+ config.register_drop :foo, FooDrop
43
+ end
59
44
  end
60
- end
61
-
62
- it "should render the name" do
63
- Liquify.render("{{ item.name }}").should =~ /Spec Drop/
64
- end
65
- end
66
45
 
67
- context "when adding a tag" do
68
- before(:all) do
69
- Liquify.setup do
70
- register_tag :tag_name, SpecTag
46
+ it 'makes a new instance of the FooDrop' do
47
+ Liquify.invoke(@template)
71
48
  end
72
- end
73
49
 
74
- it "should render tag_name" do
75
- Liquify.render("{% tag_name 'dane' %}").should =~ /Spec Tag: Dane/
50
+ it 'renders "Foo" as the first name in the template' do
51
+ Liquify.invoke(@template).should == 'Foo'
52
+ end
76
53
  end
77
54
  end
78
55
  end
79
-
80
- # # initializer.rb
81
- # Liquify.setup do
82
- # register_filter SomeFilters
83
- # register_tag :include, MyInclude
84
- # register_drop :site, SiteDrop
85
- # template_root ''
86
- # end
87
-
88
- # liquify :file => 'my/path/to/file'
89
- # liquify '{{ my_source_code }}'
90
- # liquify :template => 'dane/file'
91
-
92
- # Liquify.render(:file => "my/path/to/file")
93
- # Liquify.render("{{ this is my whatever }}")
data/spec/spec_helper.rb CHANGED
@@ -1,8 +1,10 @@
1
- $LOAD_PATH.unshift(File.dirname(__FILE__))
2
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
1
+ #$:.unshift(File.dirname(__FILE__))
2
+ #$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+
4
+ require 'rails'
5
+ require 'active_record'
6
+ require 'liquid'
7
+ require 'liquid/tag'
3
8
  require 'liquify'
4
- require 'liquify/tag'
5
9
 
6
- require 'liquid/spec_filter'
7
- require 'liquid/spec_tag'
8
- require 'liquid/spec_drop'
10
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
@@ -0,0 +1,9 @@
1
+ class FooDrop < Liquid::Drop
2
+ def foo
3
+ "foo"
4
+ end
5
+
6
+ def bar
7
+ "bar"
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module FooFilters
2
+ def foo(value)
3
+ value
4
+ end
5
+
6
+ def bar(value)
7
+ value
8
+ end
9
+ end
@@ -0,0 +1,14 @@
1
+ class BarDrop
2
+ include Liquify::Methods
3
+ liquify_method :first_name, :last_name,
4
+ :full_name => lambda { |drop| "#{drop.first_name} #{drop.last_name}" },
5
+ :age => lambda { '25' }
6
+
7
+ def first_name
8
+ 'Foo'
9
+ end
10
+
11
+ def last_name
12
+ 'Bar'
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ class FooTag < Liquify::Tag
2
+ def invoke(params)
3
+ options = params.extract_options!
4
+ output = params.first
5
+ output << ' ' << options['bar'] if options['bar']
6
+ output << ' ' << options['user']['first_name'] if options['user']
7
+ return output
8
+ end
9
+ end
@@ -0,0 +1 @@
1
+ class Foo < ActiveRecord::Base; end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'active_record_hook' do
4
+ describe '.liquify_method' do
5
+ it 'responds to liquify_method' do
6
+ Foo.respond_to?(:liquify_method).should == true
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe Liquify::Methods do
4
+ describe '.liquify_method' do
5
+ before(:each) do
6
+ Liquify.setup do |config|
7
+ config.register_drop :bar, BarDrop
8
+ end
9
+ end
10
+
11
+ it 'returns the value of a method on the drop instance' do
12
+ template = '{{ bar.first_name }} {{ bar.last_name }}'
13
+ Liquify.render(template).should == 'Foo Bar'
14
+ end
15
+
16
+ it 'returns the output of a labmda with an argument passed' do
17
+ Liquify.render('{{ bar.full_name }}').should == 'Foo Bar'
18
+ end
19
+
20
+ it 'returns the output of a labmda without an argument passed' do
21
+ Liquify.render('{{ bar.age }}').should == '25'
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+
3
+ describe Liquify do
4
+ describe '.register_tag' do
5
+ it 'adds a tag to liquify' do
6
+ Liquify.setup do |config|
7
+ config.register_tag :foo, FooTag
8
+ end
9
+
10
+ Liquify.class_variable_get(:@@tags).include?(:foo).should == true
11
+ end
12
+ end
13
+
14
+ describe '.register_filters' do
15
+ it 'adds a set of filters to liquify' do
16
+ Liquify.setup do |config|
17
+ config.register_filters FooFilters
18
+ end
19
+
20
+ Liquify.class_variable_get(:@@filters).include?(FooFilters).should == true
21
+ end
22
+ end
23
+
24
+ describe '.register_drop' do
25
+ it 'adds a drop to liquify' do
26
+ Liquify.setup do |config|
27
+ config.register_drop :foo, FooDrop
28
+ end
29
+
30
+ Liquify.class_variable_get(:@@drops).include?(:foo).should == true
31
+ end
32
+ end
33
+
34
+ describe '.render' do
35
+ context 'when a drop is registered as a class' do
36
+ before(:each) do
37
+ foo_drop = mock(FooDrop, :to_liquid => {'first_name' => 'Foo'})
38
+ FooDrop.should_receive(:new).and_return(foo_drop)
39
+ @template = '{{ foo.first_name }}'
40
+
41
+ Liquify.setup do |config|
42
+ config.register_drop :foo, FooDrop
43
+ end
44
+ end
45
+
46
+ it 'makes a new instance of the FooDrop' do
47
+ Liquify.render(@template)
48
+ end
49
+
50
+ it 'renders "Foo" as the first name in the template' do
51
+ Liquify.render(@template).should == 'Foo'
52
+ end
53
+ end
54
+ end
55
+ end
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: liquify
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 1
9
- version: "0.1"
4
+ prerelease:
5
+ version: "0.2"
10
6
  platform: ruby
11
7
  authors:
12
8
  - Dane Harrigan
@@ -14,72 +10,78 @@ autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
12
 
17
- date: 2010-07-11 00:00:00 -04:00
13
+ date: 2011-03-06 00:00:00 -05:00
18
14
  default_executable:
19
15
  dependencies:
20
16
  - !ruby/object:Gem::Dependency
21
- name: rspec
17
+ name: liquid
22
18
  prerelease: false
23
19
  requirement: &id001 !ruby/object:Gem::Requirement
24
20
  none: false
25
21
  requirements:
26
22
  - - ">="
27
23
  - !ruby/object:Gem::Version
28
- hash: 27
29
- segments:
30
- - 1
31
- - 3
32
- - 0
33
- version: 1.3.0
34
- type: :development
24
+ version: 2.2.2
25
+ type: :runtime
35
26
  version_requirements: *id001
36
27
  - !ruby/object:Gem::Dependency
37
- name: liquid
28
+ name: rspec
38
29
  prerelease: false
39
30
  requirement: &id002 !ruby/object:Gem::Requirement
40
31
  none: false
41
32
  requirements:
42
- - - "="
33
+ - - ~>
43
34
  - !ruby/object:Gem::Version
44
- hash: 15
45
- segments:
46
- - 2
47
- - 1
48
- - 2
49
- version: 2.1.2
50
- type: :runtime
35
+ version: 2.3.0
36
+ type: :development
51
37
  version_requirements: *id002
52
- description: Liquify is a wrapper to Liquid Markup to make it easier to use
53
- email: dane.harrigan@gmail.com
38
+ description: A wrapper for Liquid Markup to make it easier to use
39
+ email:
40
+ - dane.harrigan@gmail.com
54
41
  executables: []
55
42
 
56
43
  extensions: []
57
44
 
58
- extra_rdoc_files:
59
- - LICENSE
60
- - README.rdoc
45
+ extra_rdoc_files: []
46
+
61
47
  files:
62
- - .document
63
48
  - .gitignore
64
- - LICENSE
65
- - README.rdoc
49
+ - Gemfile
50
+ - Gemfile.lock
51
+ - README.textile
66
52
  - Rakefile
53
+ - init.rb
54
+ - lib/generators/liquify/install_generator.rb
55
+ - lib/generators/liquify/templates/liquify.rb
67
56
  - lib/liquify.rb
57
+ - lib/liquify/drop.rb
58
+ - lib/liquify/methods.rb
59
+ - lib/liquify/parameter.rb
68
60
  - lib/liquify/tag.rb
69
- - spec/liquid/spec_drop.rb
70
- - spec/liquid/spec_filter.rb
71
- - spec/liquid/spec_tag.rb
72
- - spec/liquid/templates/sample.liquid
61
+ - lib/liquify/version.rb
62
+ - lib/rails/active_record_hook.rb
63
+ - liquify.gemspec
64
+ - spec/liquify/active_record_hook_spec.rb
65
+ - spec/liquify/drop_spec.rb
66
+ - spec/liquify/parameter_spec.rb
73
67
  - spec/liquify/tag_spec.rb
74
68
  - spec/liquify_spec.rb
75
69
  - spec/spec_helper.rb
70
+ - spec/support/liquid/foo_drop.rb
71
+ - spec/support/liquid/foo_filters.rb
72
+ - spec/support/liquify/bar_drop.rb
73
+ - spec/support/liquify/foo_tag.rb
74
+ - spec/support/rails/foo.rb
75
+ - spec/v0.1/liquify/active_record_hook_spec.rb
76
+ - spec/v0.1/liquify/drop_spec.rb
77
+ - spec/v0.1/liquify_spec.rb
76
78
  has_rdoc: true
77
- homepage: http://github.com/daneharrigan/liquify
79
+ homepage: ""
78
80
  licenses: []
79
81
 
80
82
  post_install_message:
81
- rdoc_options:
82
- - --charset=UTF-8
83
+ rdoc_options: []
84
+
83
85
  require_paths:
84
86
  - lib
85
87
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -87,30 +89,32 @@ required_ruby_version: !ruby/object:Gem::Requirement
87
89
  requirements:
88
90
  - - ">="
89
91
  - !ruby/object:Gem::Version
90
- hash: 3
91
- segments:
92
- - 0
93
92
  version: "0"
94
93
  required_rubygems_version: !ruby/object:Gem::Requirement
95
94
  none: false
96
95
  requirements:
97
96
  - - ">="
98
97
  - !ruby/object:Gem::Version
99
- hash: 3
100
- segments:
101
- - 0
102
98
  version: "0"
103
99
  requirements: []
104
100
 
105
- rubyforge_project:
106
- rubygems_version: 1.3.7
101
+ rubyforge_project: liquify
102
+ rubygems_version: 1.5.2
107
103
  signing_key:
108
104
  specification_version: 3
109
- summary: Liquify is a wrapper to Liquid Markup to make it easier to use
105
+ summary: A wrapper for Liquid Markup to make it easier to use
110
106
  test_files:
111
- - spec/liquid/spec_drop.rb
112
- - spec/liquid/spec_filter.rb
113
- - spec/liquid/spec_tag.rb
107
+ - spec/liquify/active_record_hook_spec.rb
108
+ - spec/liquify/drop_spec.rb
109
+ - spec/liquify/parameter_spec.rb
114
110
  - spec/liquify/tag_spec.rb
115
111
  - spec/liquify_spec.rb
116
112
  - spec/spec_helper.rb
113
+ - spec/support/liquid/foo_drop.rb
114
+ - spec/support/liquid/foo_filters.rb
115
+ - spec/support/liquify/bar_drop.rb
116
+ - spec/support/liquify/foo_tag.rb
117
+ - spec/support/rails/foo.rb
118
+ - spec/v0.1/liquify/active_record_hook_spec.rb
119
+ - spec/v0.1/liquify/drop_spec.rb
120
+ - spec/v0.1/liquify_spec.rb
data/.document DELETED
@@ -1,5 +0,0 @@
1
- README.rdoc
2
- lib/**/*.rb
3
- bin/*
4
- features/**/*.feature
5
- LICENSE
data/LICENSE DELETED
@@ -1,20 +0,0 @@
1
- Copyright (c) 2009 Dane Harrigan
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc DELETED
@@ -1,64 +0,0 @@
1
- = liquify
2
-
3
- Liquify is a wrapper to Tobi's <a href="http://rubygems/liquid">Liquid Markup</a> gem.
4
-
5
- == Examples
6
-
7
- ## configuring Liquify
8
- Liquify.setup do
9
- register_filter MyFilters
10
- register_tag :include, IncludeTag
11
- register_drop :page, PageDrop
12
- end
13
-
14
- # Any filter, tag or drop registered to Liquify is available anything
15
- # rendered through +Liquify.render+.
16
-
17
- ## Using Liquify
18
- # rendering source
19
- Liquify.render("{{ page.name }}")
20
-
21
- # rendering from a file (from a full path)
22
- Liquify.render(:template => '/path/to/file.liquid')
23
-
24
- # rendering from a file (from a relative path)
25
- # setup template root location
26
- Liquify.setup do
27
- template_root '/path/to/templates'
28
- end
29
-
30
- Liquify.render(:template => 'relative/path/file.liquid')
31
-
32
- ## my_filters.rb
33
- module MyFilters
34
- def bold_text(text)
35
- text = Liquify.parameter(text)
36
- "<strong>#{text}</strong>"
37
- end
38
- end
39
-
40
- ## include_tag.rb
41
- class IncludeTag < Liquify::Tag
42
- def invoke
43
- Liquify.render("#{parameter}.liquid")
44
- end
45
- end
46
-
47
- == Todo
48
-
49
- Make a helpful classes that improve on Liquid's Drop and Block class.
50
-
51
-
52
- == Note on Patches/Pull Requests
53
-
54
- * Fork the project.
55
- * Make your feature addition or bug fix.
56
- * Add tests for it. This is important so I don't break it in a
57
- future version unintentionally.
58
- * Commit, do not mess with rakefile, version, or history.
59
- (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
60
- * Send me a pull request. Bonus points for topic branches.
61
-
62
- == Copyright
63
-
64
- Copyright (c) 2010 Dane Harrigan. See LICENSE for details.
@@ -1,5 +0,0 @@
1
- class SpecDrop < Liquid::Drop
2
- def name
3
- "Spec Drop: #{param}"
4
- end
5
- end
@@ -1,6 +0,0 @@
1
- module SpecFilter
2
- def bold_text(text)
3
- text = Liquify.parameter(text)
4
- "<strong>#{text}</strong>"
5
- end
6
- end
@@ -1,5 +0,0 @@
1
- class SpecTag < Liquify::Tag
2
- def invoke
3
- "Spec Tag: #{parameter.capitalize}"
4
- end
5
- end
@@ -1 +0,0 @@
1
- {{ 'sample text' }}