alephant-renderer 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/README.md +92 -24
- data/lib/alephant/renderer/version.rb +1 -1
- data/lib/alephant/renderer/view_mapper.rb +6 -1
- metadata +36 -36
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a2a935dbcec456b0e6b3a680e6909c5447c42b8
|
4
|
+
data.tar.gz: 683fd54508a44969a79fa8eb6b4d1d83123851ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc2155534f400ebc1c1fe29424698924d40f0cf49e1988ef6032948ca4344da6686bec32b4527b669e1e3533a66738226b7fd9645603560442ba567f02073328
|
7
|
+
data.tar.gz: ccd773c830fa23e553fce955667cdeec785c0c5f8ff3bf25714e31838d6762eb26cb2419bf9e88800597a80b0d378389f2accade8954983ce0005dd7129cc305
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
jruby-1.7
|
1
|
+
jruby-1.7
|
data/README.md
CHANGED
@@ -1,10 +1,8 @@
|
|
1
1
|
# Alephant::Renderer
|
2
2
|
|
3
|
-
Render HTML
|
3
|
+
Render snippets of HTML/JSON using templates.
|
4
4
|
|
5
|
-
[![Build Status](https://travis-ci.org/BBC-News/alephant-renderer.png?branch=master)](https://travis-ci.org/BBC-News/alephant-renderer)
|
6
|
-
|
7
|
-
[![Gem Version](https://badge.fury.io/rb/alephant-renderer.png)](http://badge.fury.io/rb/alephant-renderer)
|
5
|
+
[![Build Status](https://travis-ci.org/BBC-News/alephant-renderer.png?branch=master)](https://travis-ci.org/BBC-News/alephant-renderer) [![Gem Version](https://badge.fury.io/rb/alephant-renderer.png)](http://badge.fury.io/rb/alephant-renderer)
|
8
6
|
|
9
7
|
## Installation
|
10
8
|
|
@@ -14,20 +12,88 @@ Add this line to your application's Gemfile:
|
|
14
12
|
|
15
13
|
And then execute:
|
16
14
|
|
17
|
-
|
15
|
+
bundle
|
18
16
|
|
19
17
|
Or install it yourself as:
|
20
18
|
|
21
|
-
|
19
|
+
gem install alephant-renderer
|
20
|
+
|
21
|
+
## Setup
|
22
|
+
|
23
|
+
This gem requires you to have at least one component, which has within it at least one view/template pair.
|
24
|
+
|
25
|
+
```bash
|
26
|
+
src
|
27
|
+
├── components
|
28
|
+
│ ├── weather
|
29
|
+
│ │ ├── models
|
30
|
+
│ │ │ ├── daily_summary.rb
|
31
|
+
│ │ │ ├── weekly_summary.rb
|
32
|
+
│ │ ├── templates
|
33
|
+
│ │ │ ├── daily_summary.mustache
|
34
|
+
│ │ │ ├── weekly_summary.mustache
|
35
|
+
```
|
36
|
+
|
37
|
+
> daily_summary.rb
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
require 'alephant/renderer/views/html'
|
41
|
+
require 'date'
|
42
|
+
|
43
|
+
class DailySummary < Alephant::Renderer::Views::Html
|
44
|
+
def temp
|
45
|
+
@data[:time].round 0
|
46
|
+
end
|
47
|
+
|
48
|
+
def time
|
49
|
+
DateTime.now.strftime "%d/%m/%Y %H:%M"
|
50
|
+
end
|
51
|
+
|
52
|
+
def summary
|
53
|
+
@data[:summary].capitalize
|
54
|
+
end
|
55
|
+
end
|
56
|
+
```
|
57
|
+
|
58
|
+
> daily_summary.mustache
|
59
|
+
|
60
|
+
```mustache
|
61
|
+
Weather for {{ time }}
|
62
|
+
{{ summary }} - {{ temp }}°
|
63
|
+
```
|
22
64
|
|
23
65
|
## Usage
|
24
66
|
|
25
|
-
```
|
67
|
+
```ruby
|
26
68
|
require 'alephant/renderer'
|
69
|
+
require 'json'
|
70
|
+
|
71
|
+
config = {
|
72
|
+
:renderer_id => 'weather',
|
73
|
+
:view_path => 'src/components'
|
74
|
+
}
|
75
|
+
|
76
|
+
data = {
|
77
|
+
:summary => 'Light rain starting tonight.',
|
78
|
+
:temp => '11.86'
|
79
|
+
}.to_json
|
27
80
|
|
28
|
-
Alephant::Renderer.create(
|
81
|
+
Alephant::Renderer.create(
|
82
|
+
config, data
|
83
|
+
).views['daily_summary'].render
|
29
84
|
```
|
30
85
|
|
86
|
+
**Note** - Within you application you will be most likely providing the *data* dynamically and thus will not require the JSON library.
|
87
|
+
|
88
|
+
#### Example Application
|
89
|
+
|
90
|
+
The [alephant-publisher-request](https://github.com/BBC-News/alephant-publisher-request) gem is an example of an application which utilises this gem. Overview of process:
|
91
|
+
|
92
|
+
1. Receives request from user, via [Rack](http://rack.github.io/).
|
93
|
+
2. Fetches required data dynamically from a given API.
|
94
|
+
3. Renders specified component using data.
|
95
|
+
4. Returns rendered template.
|
96
|
+
|
31
97
|
## Translations
|
32
98
|
|
33
99
|
Currently there is a simple implementation of the [i18n](https://github.com/svenfuchs/i18n) library that allows templates to be translated.
|
@@ -51,13 +117,13 @@ The yaml translations files must follow the following structure:
|
|
51
117
|
|
52
118
|
```yaml
|
53
119
|
en:
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
120
|
+
template_name:
|
121
|
+
key: 'foo'
|
122
|
+
sub:
|
123
|
+
key: 'bar'
|
58
124
|
|
59
|
-
|
60
|
-
|
125
|
+
another_template:
|
126
|
+
key: 'baz'
|
61
127
|
```
|
62
128
|
|
63
129
|
The first node is the language code, then the next set of nodes are the names of the templates files that the translations apply to. This allows you to just reference the translation key in the templates without prefixing the name of the template.
|
@@ -70,7 +136,7 @@ For each translation, a seperate model and view is needed.
|
|
70
136
|
|
71
137
|
All that's needed in the model is to override the LOCALE constant:
|
72
138
|
|
73
|
-
```
|
139
|
+
```ruby
|
74
140
|
class TestModel < Alephant::Views::Base
|
75
141
|
LOCALE = :cy
|
76
142
|
end
|
@@ -94,7 +160,7 @@ If we had a template called 'test_template.mustache' we would have the following
|
|
94
160
|
|
95
161
|
```ruby
|
96
162
|
def my_translation
|
97
|
-
|
163
|
+
t 'key'
|
98
164
|
end
|
99
165
|
```
|
100
166
|
|
@@ -108,8 +174,8 @@ end
|
|
108
174
|
|
109
175
|
```yaml
|
110
176
|
en:
|
111
|
-
|
112
|
-
|
177
|
+
test_template:
|
178
|
+
key: 'A translation!'
|
113
179
|
```
|
114
180
|
|
115
181
|
##### Default
|
@@ -120,7 +186,7 @@ You can override this behaviour and provide a default:
|
|
120
186
|
|
121
187
|
```ruby
|
122
188
|
def my_translation
|
123
|
-
|
189
|
+
t 'missing_key', :default => 'Some default'
|
124
190
|
end
|
125
191
|
|
126
192
|
```
|
@@ -130,8 +196,10 @@ So if the key doesn't exists, then 'Some default' is the translation.
|
|
130
196
|
|
131
197
|
## Contributing
|
132
198
|
|
133
|
-
1. Fork it
|
134
|
-
2. Create your feature branch
|
135
|
-
3. Commit your changes
|
136
|
-
4. Push to the branch
|
137
|
-
5. Create new Pull Request
|
199
|
+
1. [Fork it!](http://github.com/bbc-news/alephant-renderer/fork)
|
200
|
+
2. Create your feature branch: `git checkout -b my-new-feature`
|
201
|
+
3. Commit your changes: `git commit -am 'Add some feature'`
|
202
|
+
4. Push to the branch: `git push origin my-new-feature`
|
203
|
+
5. Create new [Pull Request](https://github.com/BBC-News/alephant-renderer/pulls).
|
204
|
+
|
205
|
+
Feel free to create an [issue](https://github.com/BBC-News/alephant-renderer/issues/new) if you find a bug.
|
@@ -17,7 +17,7 @@ module Alephant
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def base_path=(path)
|
20
|
-
@base_path = File.directory?(path) ? path : (
|
20
|
+
@base_path = File.directory?(path) ? path : raise_error(path)
|
21
21
|
end
|
22
22
|
|
23
23
|
def generate(data)
|
@@ -31,6 +31,11 @@ module Alephant
|
|
31
31
|
|
32
32
|
private
|
33
33
|
|
34
|
+
def raise_error(path)
|
35
|
+
logger.metric({:name => "RenderViewMapperInvalidPath", :unit => "Count", :value => 1})
|
36
|
+
raise "Invalid path: '#{path}'"
|
37
|
+
end
|
38
|
+
|
34
39
|
def model(view_id, data)
|
35
40
|
require model_location_for view_id
|
36
41
|
Views.get_registered_class(view_id).new(data)
|
metadata
CHANGED
@@ -1,212 +1,212 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alephant-renderer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Kenny
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name: rspec
|
15
14
|
requirement: !ruby/object:Gem::Requirement
|
16
15
|
requirements:
|
17
16
|
- - '>='
|
18
17
|
- !ruby/object:Gem::Version
|
19
18
|
version: '0'
|
20
|
-
|
19
|
+
name: rspec
|
21
20
|
prerelease: false
|
21
|
+
type: :development
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name: rspec-nc
|
29
28
|
requirement: !ruby/object:Gem::Requirement
|
30
29
|
requirements:
|
31
30
|
- - '>='
|
32
31
|
- !ruby/object:Gem::Version
|
33
32
|
version: '0'
|
34
|
-
|
33
|
+
name: rspec-nc
|
35
34
|
prerelease: false
|
35
|
+
type: :development
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name: guard
|
43
42
|
requirement: !ruby/object:Gem::Requirement
|
44
43
|
requirements:
|
45
44
|
- - '>='
|
46
45
|
- !ruby/object:Gem::Version
|
47
46
|
version: '0'
|
48
|
-
|
47
|
+
name: guard
|
49
48
|
prerelease: false
|
49
|
+
type: :development
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name: guard-rspec
|
57
56
|
requirement: !ruby/object:Gem::Requirement
|
58
57
|
requirements:
|
59
58
|
- - '>='
|
60
59
|
- !ruby/object:Gem::Version
|
61
60
|
version: '0'
|
62
|
-
|
61
|
+
name: guard-rspec
|
63
62
|
prerelease: false
|
63
|
+
type: :development
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name: pry
|
71
70
|
requirement: !ruby/object:Gem::Requirement
|
72
71
|
requirements:
|
73
72
|
- - '>='
|
74
73
|
- !ruby/object:Gem::Version
|
75
74
|
version: '0'
|
76
|
-
|
75
|
+
name: pry
|
77
76
|
prerelease: false
|
77
|
+
type: :development
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - '>='
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name: pry-remote
|
85
84
|
requirement: !ruby/object:Gem::Requirement
|
86
85
|
requirements:
|
87
86
|
- - '>='
|
88
87
|
- !ruby/object:Gem::Version
|
89
88
|
version: '0'
|
90
|
-
|
89
|
+
name: pry-remote
|
91
90
|
prerelease: false
|
91
|
+
type: :development
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - '>='
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name: pry-nav
|
99
98
|
requirement: !ruby/object:Gem::Requirement
|
100
99
|
requirements:
|
101
100
|
- - '>='
|
102
101
|
- !ruby/object:Gem::Version
|
103
102
|
version: '0'
|
104
|
-
|
103
|
+
name: pry-nav
|
105
104
|
prerelease: false
|
105
|
+
type: :development
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - '>='
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
|
-
name: bundler
|
113
112
|
requirement: !ruby/object:Gem::Requirement
|
114
113
|
requirements:
|
115
114
|
- - ~>
|
116
115
|
- !ruby/object:Gem::Version
|
117
116
|
version: '1.5'
|
118
|
-
|
117
|
+
name: bundler
|
119
118
|
prerelease: false
|
119
|
+
type: :development
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - ~>
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '1.5'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
|
-
name: rake
|
127
126
|
requirement: !ruby/object:Gem::Requirement
|
128
127
|
requirements:
|
129
128
|
- - '>='
|
130
129
|
- !ruby/object:Gem::Version
|
131
130
|
version: '0'
|
132
|
-
|
131
|
+
name: rake
|
133
132
|
prerelease: false
|
133
|
+
type: :development
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
136
|
- - '>='
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
|
-
name: rake-rspec
|
141
140
|
requirement: !ruby/object:Gem::Requirement
|
142
141
|
requirements:
|
143
142
|
- - '>='
|
144
143
|
- !ruby/object:Gem::Version
|
145
144
|
version: '0'
|
146
|
-
|
145
|
+
name: rake-rspec
|
147
146
|
prerelease: false
|
147
|
+
type: :development
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
150
|
- - '>='
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '0'
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
|
-
name: i18n
|
155
154
|
requirement: !ruby/object:Gem::Requirement
|
156
155
|
requirements:
|
157
156
|
- - '>='
|
158
157
|
- !ruby/object:Gem::Version
|
159
158
|
version: '0'
|
160
|
-
|
159
|
+
name: i18n
|
161
160
|
prerelease: false
|
161
|
+
type: :runtime
|
162
162
|
version_requirements: !ruby/object:Gem::Requirement
|
163
163
|
requirements:
|
164
164
|
- - '>='
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: '0'
|
167
167
|
- !ruby/object:Gem::Dependency
|
168
|
-
name: mustache
|
169
168
|
requirement: !ruby/object:Gem::Requirement
|
170
169
|
requirements:
|
171
170
|
- - '>='
|
172
171
|
- !ruby/object:Gem::Version
|
173
172
|
version: 0.99.5
|
174
|
-
|
173
|
+
name: mustache
|
175
174
|
prerelease: false
|
175
|
+
type: :runtime
|
176
176
|
version_requirements: !ruby/object:Gem::Requirement
|
177
177
|
requirements:
|
178
178
|
- - '>='
|
179
179
|
- !ruby/object:Gem::Version
|
180
180
|
version: 0.99.5
|
181
181
|
- !ruby/object:Gem::Dependency
|
182
|
-
name: alephant-logger
|
183
182
|
requirement: !ruby/object:Gem::Requirement
|
184
183
|
requirements:
|
185
184
|
- - '>='
|
186
185
|
- !ruby/object:Gem::Version
|
187
186
|
version: '0'
|
188
|
-
|
187
|
+
name: alephant-logger
|
189
188
|
prerelease: false
|
189
|
+
type: :runtime
|
190
190
|
version_requirements: !ruby/object:Gem::Requirement
|
191
191
|
requirements:
|
192
192
|
- - '>='
|
193
193
|
- !ruby/object:Gem::Version
|
194
194
|
version: '0'
|
195
195
|
- !ruby/object:Gem::Dependency
|
196
|
-
name: hashie
|
197
196
|
requirement: !ruby/object:Gem::Requirement
|
198
197
|
requirements:
|
199
198
|
- - '>='
|
200
199
|
- !ruby/object:Gem::Version
|
201
200
|
version: '0'
|
202
|
-
|
201
|
+
name: hashie
|
203
202
|
prerelease: false
|
203
|
+
type: :runtime
|
204
204
|
version_requirements: !ruby/object:Gem::Requirement
|
205
205
|
requirements:
|
206
206
|
- - '>='
|
207
207
|
- !ruby/object:Gem::Version
|
208
208
|
version: '0'
|
209
|
-
description:
|
209
|
+
description:
|
210
210
|
email:
|
211
211
|
- kenoir@gmail.com
|
212
212
|
executables: []
|
@@ -242,7 +242,7 @@ homepage: ''
|
|
242
242
|
licenses:
|
243
243
|
- MIT
|
244
244
|
metadata: {}
|
245
|
-
post_install_message:
|
245
|
+
post_install_message:
|
246
246
|
rdoc_options: []
|
247
247
|
require_paths:
|
248
248
|
- lib
|
@@ -257,9 +257,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
257
257
|
- !ruby/object:Gem::Version
|
258
258
|
version: '0'
|
259
259
|
requirements: []
|
260
|
-
rubyforge_project:
|
261
|
-
rubygems_version: 2.
|
262
|
-
signing_key:
|
260
|
+
rubyforge_project:
|
261
|
+
rubygems_version: 2.1.9
|
262
|
+
signing_key:
|
263
263
|
specification_version: 4
|
264
264
|
summary: Render HTML snippets
|
265
265
|
test_files:
|