alephant-renderer 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.ruby-version +1 -0
- data/.travis.yml +9 -0
- data/Gemfile +4 -0
- data/Guardfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +37 -0
- data/Rakefile +9 -0
- data/alephant-renderer.gemspec +30 -0
- data/lib/alephant/renderer.rb +12 -0
- data/lib/alephant/renderer/engines/mustache.rb +38 -0
- data/lib/alephant/renderer/version.rb +5 -0
- data/spec/fixtures/components/foo/models/foo.rb +7 -0
- data/spec/fixtures/components/foo/templates/bar.mustache +1 -0
- data/spec/fixtures/components/foo/templates/foo.mustache +1 -0
- data/spec/renderer_spec.rb +58 -0
- data/spec/spec_helper.rb +5 -0
- metadata +192 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e22139dfc1e97138eb2a3ddcdb39f408255ce81b
|
4
|
+
data.tar.gz: c627489d2092e3414562e9e7fc3a9a1ff3b5d6b3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 134a33c4a1f67b96019082f7c7e01e12b15e831e60dcb80ecbcf37afb090b5dc3e1b6e31fc52b0cdc083a228559bf469548c32f7eb7dba407aee8cfa6c5e7106
|
7
|
+
data.tar.gz: 62a7e0496e498da2adcef46f825a4d463a841cf0cb0158a683f76fbba94d52317f52918e2b445b3b496e390d502df8a513b7c56d8cc81be38f94a5811259f1d5
|
data/.gitignore
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
jruby-1.7.9
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Robert Kenny
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# Alephant::Renderer
|
2
|
+
|
3
|
+
Render HTML snippets
|
4
|
+
|
5
|
+
[](https://travis-ci.org/BBC-News/alephant-renderer)
|
6
|
+
|
7
|
+
[](http://badge.fury.io/rb/alephant-renderer)
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
gem 'alephant-renderer'
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install alephant-renderer
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
```rb
|
26
|
+
require 'alephant/renderer'
|
27
|
+
|
28
|
+
Alephant::Renderer.create('foo_template', '/base/path', 'foo_model')
|
29
|
+
```
|
30
|
+
|
31
|
+
## Contributing
|
32
|
+
|
33
|
+
1. Fork it ( http://github.com/<my-github-username>/alephant-renderer/fork )
|
34
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
35
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
36
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
37
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'alephant/renderer/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "alephant-renderer"
|
8
|
+
spec.version = Alephant::Renderer::VERSION
|
9
|
+
spec.authors = ["Robert Kenny"]
|
10
|
+
spec.email = ["kenoir@gmail.com"]
|
11
|
+
spec.summary = "Render HTML snippets"
|
12
|
+
spec.homepage = ""
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "rspec"
|
21
|
+
spec.add_development_dependency "rspec-nc"
|
22
|
+
spec.add_development_dependency "guard"
|
23
|
+
spec.add_development_dependency "guard-rspec"
|
24
|
+
spec.add_development_dependency "pry"
|
25
|
+
spec.add_development_dependency "pry-remote"
|
26
|
+
spec.add_development_dependency "pry-nav"
|
27
|
+
|
28
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
29
|
+
spec.add_development_dependency "rake"
|
30
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'alephant/logger'
|
2
|
+
require 'mustache'
|
3
|
+
|
4
|
+
module Alephant
|
5
|
+
module Renderer
|
6
|
+
class Mustache
|
7
|
+
include ::Alephant::Logger
|
8
|
+
|
9
|
+
attr_reader :template_file
|
10
|
+
|
11
|
+
def initialize(template_file, base_path, model)
|
12
|
+
@template_file = template_file
|
13
|
+
@base_path = base_path
|
14
|
+
@model = model
|
15
|
+
|
16
|
+
logger.info("Renderer.initialize: end with @base_path set to #{@base_path}")
|
17
|
+
end
|
18
|
+
|
19
|
+
def render
|
20
|
+
logger.info("Renderer.render: rendered template #{template_file}")
|
21
|
+
::Mustache.render(template, @model)
|
22
|
+
end
|
23
|
+
|
24
|
+
def template
|
25
|
+
template_location = File.join(@base_path, 'templates', "#{template_file}.mustache")
|
26
|
+
|
27
|
+
begin
|
28
|
+
logger.info("Renderer.template: #{template_location}")
|
29
|
+
File.open(template_location).read
|
30
|
+
rescue Exception => e
|
31
|
+
logger.error("Renderer.template: view template #{template_file} not found")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
{{content}}
|
@@ -0,0 +1 @@
|
|
1
|
+
{{content}}
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Alephant::Renderer do
|
4
|
+
let(:template_file) { 'foo' }
|
5
|
+
let(:base_path) { :base_path }
|
6
|
+
let(:model) { :model }
|
7
|
+
|
8
|
+
before(:each) do
|
9
|
+
@base_path = File.join(
|
10
|
+
File.dirname(__FILE__),
|
11
|
+
'fixtures',
|
12
|
+
'components',
|
13
|
+
'foo'
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
describe ".create(template_file, base_path, model)" do
|
18
|
+
it "returns a Alephant::Renderer::Mustache" do
|
19
|
+
expect(subject.create(template_file, base_path, model)).to be_a Alephant::Renderer::Mustache
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe Alephant::Renderer::Mustache do
|
24
|
+
subject { Alephant::Renderer::Mustache }
|
25
|
+
describe "initialize(template_file, base_path, model)" do
|
26
|
+
context "template_file = :template_file" do
|
27
|
+
it "sets the attribute template_file" do
|
28
|
+
expect(subject.new(template_file, base_path, model).template_file).to eq(template_file)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "template()" do
|
34
|
+
it "returns the template" do
|
35
|
+
instance = subject.new(template_file, @base_path, model)
|
36
|
+
template = instance.template
|
37
|
+
expect(template).to eq("{{content}}\n")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "render()" do
|
42
|
+
it 'renders a template returned from template(template_file)' do
|
43
|
+
::Mustache
|
44
|
+
.any_instance
|
45
|
+
.stub(:render)
|
46
|
+
.with(:template, :model)
|
47
|
+
.and_return(:content)
|
48
|
+
|
49
|
+
Alephant::Renderer::Mustache
|
50
|
+
.any_instance
|
51
|
+
.stub(:template)
|
52
|
+
.and_return(:template)
|
53
|
+
|
54
|
+
expect(subject.new(template_file, @base_path, model).render).to eq(:content)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,192 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: alephant-renderer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Robert Kenny
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-02-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
version_requirements: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
requirement: !ruby/object:Gem::Requirement
|
21
|
+
requirements:
|
22
|
+
- - '>='
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: '0'
|
25
|
+
prerelease: false
|
26
|
+
type: :development
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec-nc
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
prerelease: false
|
40
|
+
type: :development
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: guard
|
43
|
+
version_requirements: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
prerelease: false
|
54
|
+
type: :development
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: guard-rspec
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
requirement: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
prerelease: false
|
68
|
+
type: :development
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
version_requirements: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
requirement: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
prerelease: false
|
82
|
+
type: :development
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry-remote
|
85
|
+
version_requirements: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirement: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
prerelease: false
|
96
|
+
type: :development
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry-nav
|
99
|
+
version_requirements: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirement: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - '>='
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
prerelease: false
|
110
|
+
type: :development
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: bundler
|
113
|
+
version_requirements: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ~>
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '1.5'
|
118
|
+
requirement: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ~>
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '1.5'
|
123
|
+
prerelease: false
|
124
|
+
type: :development
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rake
|
127
|
+
version_requirements: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
requirement: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - '>='
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
prerelease: false
|
138
|
+
type: :development
|
139
|
+
description:
|
140
|
+
email:
|
141
|
+
- kenoir@gmail.com
|
142
|
+
executables: []
|
143
|
+
extensions: []
|
144
|
+
extra_rdoc_files: []
|
145
|
+
files:
|
146
|
+
- .gitignore
|
147
|
+
- .ruby-version
|
148
|
+
- .travis.yml
|
149
|
+
- Gemfile
|
150
|
+
- Guardfile
|
151
|
+
- LICENSE.txt
|
152
|
+
- README.md
|
153
|
+
- Rakefile
|
154
|
+
- alephant-renderer.gemspec
|
155
|
+
- lib/alephant/renderer.rb
|
156
|
+
- lib/alephant/renderer/engines/mustache.rb
|
157
|
+
- lib/alephant/renderer/version.rb
|
158
|
+
- spec/fixtures/components/foo/models/foo.rb
|
159
|
+
- spec/fixtures/components/foo/templates/bar.mustache
|
160
|
+
- spec/fixtures/components/foo/templates/foo.mustache
|
161
|
+
- spec/renderer_spec.rb
|
162
|
+
- spec/spec_helper.rb
|
163
|
+
homepage: ''
|
164
|
+
licenses:
|
165
|
+
- MIT
|
166
|
+
metadata: {}
|
167
|
+
post_install_message:
|
168
|
+
rdoc_options: []
|
169
|
+
require_paths:
|
170
|
+
- lib
|
171
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
172
|
+
requirements:
|
173
|
+
- - '>='
|
174
|
+
- !ruby/object:Gem::Version
|
175
|
+
version: '0'
|
176
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - '>='
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
requirements: []
|
182
|
+
rubyforge_project:
|
183
|
+
rubygems_version: 2.1.9
|
184
|
+
signing_key:
|
185
|
+
specification_version: 4
|
186
|
+
summary: Render HTML snippets
|
187
|
+
test_files:
|
188
|
+
- spec/fixtures/components/foo/models/foo.rb
|
189
|
+
- spec/fixtures/components/foo/templates/bar.mustache
|
190
|
+
- spec/fixtures/components/foo/templates/foo.mustache
|
191
|
+
- spec/renderer_spec.rb
|
192
|
+
- spec/spec_helper.rb
|