liquid_loader 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.md +1 -0
- data/Rakefile +1 -0
- data/lib/liquid_loader/context.rb +29 -0
- data/lib/liquid_loader/liquid_model.rb +7 -0
- data/lib/liquid_loader/version.rb +3 -0
- data/lib/liquid_loader.rb +6 -0
- data/lib/rails/generators/liquid/drop_generator.rb +22 -0
- data/lib/rails/generators/liquid/templates/drop.rb +15 -0
- data/liquid_loader.gemspec +25 -0
- metadata +79 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
This is LiquidLoader - a simple way to expose your models to liquid by automatically loading instances into drops.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'liquid'
|
2
|
+
|
3
|
+
module LiquidLoader
|
4
|
+
module Context
|
5
|
+
|
6
|
+
def render_liquid(template, context = nil)
|
7
|
+
ctx = (context ? context : liq)
|
8
|
+
template.render(ctx)
|
9
|
+
end
|
10
|
+
|
11
|
+
def pre_render_liquid(template, destination, context = @context)
|
12
|
+
add_context(destination => render_liquid(template, context))
|
13
|
+
end
|
14
|
+
|
15
|
+
def add_context(opts = nil)
|
16
|
+
if opts.is_a? Hash
|
17
|
+
opts.each do |k, v|
|
18
|
+
liq[k.to_s.downcase] = v
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
def liq
|
25
|
+
@liq ||= Liquid::Context.new
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rails'
|
2
|
+
|
3
|
+
module Liquid
|
4
|
+
module Generators
|
5
|
+
class DropGenerator < Rails::Generators::NamedBase
|
6
|
+
source_root File.expand_path('../templates', __FILE__)
|
7
|
+
#argument :name, :type => :string
|
8
|
+
#class_option :autodiscover, :type => :boolean, :default => true, :description => "Automatically discover attributes and add them to the Drop."
|
9
|
+
|
10
|
+
|
11
|
+
desc "This generator creates liquid drops for your models."
|
12
|
+
|
13
|
+
def create_drop
|
14
|
+
@model = file_name.camelize.constantize
|
15
|
+
@attributes = @model.attribute_names
|
16
|
+
@associations = @model.reflect_on_all_associations
|
17
|
+
template "drop.rb", "app/drops/#{file_name}_drop.rb"
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class <%= class_name %>Drop < Liquid::Drop
|
2
|
+
|
3
|
+
def initialize(drop)
|
4
|
+
@drop = drop
|
5
|
+
end
|
6
|
+
<% for att in @attributes %><% unless att.ends_with?("_id") %>
|
7
|
+
def <%= att %>
|
8
|
+
@drop['<%= att %>']
|
9
|
+
end
|
10
|
+
<% end %><% end %><% for assoc in @associations %>
|
11
|
+
def <%= assoc.name %>
|
12
|
+
@drop.<%= assoc.name %>
|
13
|
+
end
|
14
|
+
<% end %>
|
15
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "liquid_loader/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "liquid_loader"
|
7
|
+
s.version = LiquidLoader::VERSION
|
8
|
+
s.authors = ["John Maxwell"]
|
9
|
+
s.email = ["JGW Maxwell"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{This gem provides a simple include method to auto-generate liquid drops from models.}
|
12
|
+
s.description = %q{See Summary}
|
13
|
+
|
14
|
+
s.rubyforge_project = "liquid_loader"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
# s.add_development_dependency "rspec"
|
23
|
+
s.add_runtime_dependency "liquid"
|
24
|
+
s.add_runtime_dependency "rails", "~> 3.1.0"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: liquid_loader
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- John Maxwell
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-12-13 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: liquid
|
16
|
+
requirement: &13716200 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *13716200
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rails
|
27
|
+
requirement: &13715600 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 3.1.0
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *13715600
|
36
|
+
description: See Summary
|
37
|
+
email:
|
38
|
+
- JGW Maxwell
|
39
|
+
executables: []
|
40
|
+
extensions: []
|
41
|
+
extra_rdoc_files: []
|
42
|
+
files:
|
43
|
+
- .gitignore
|
44
|
+
- Gemfile
|
45
|
+
- README.md
|
46
|
+
- Rakefile
|
47
|
+
- lib/liquid_loader.rb
|
48
|
+
- lib/liquid_loader/context.rb
|
49
|
+
- lib/liquid_loader/liquid_model.rb
|
50
|
+
- lib/liquid_loader/version.rb
|
51
|
+
- lib/rails/generators/liquid/drop_generator.rb
|
52
|
+
- lib/rails/generators/liquid/templates/drop.rb
|
53
|
+
- liquid_loader.gemspec
|
54
|
+
homepage: ''
|
55
|
+
licenses: []
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ! '>='
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
requirements: []
|
73
|
+
rubyforge_project: liquid_loader
|
74
|
+
rubygems_version: 1.8.10
|
75
|
+
signing_key:
|
76
|
+
specification_version: 3
|
77
|
+
summary: This gem provides a simple include method to auto-generate liquid drops from
|
78
|
+
models.
|
79
|
+
test_files: []
|