alephant-publisher 0.6.3 → 0.6.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/alephant/publisher/version.rb +1 -1
- data/lib/alephant/publisher/views/base.rb +30 -27
- data/lib/alephant/publisher/views/html.rb +54 -51
- data/lib/alephant/publisher/views/json.rb +13 -10
- data/lib/alephant/publisher/views.rb +0 -3
- data/lib/alephant/publisher.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9fe2812878ad4f51f2ac6a319f3815469be493a8
|
4
|
+
data.tar.gz: d8ab5c8158028eb611f02ee4d6a0b9a92ccdd40a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b7b9cc3b1787c30fc4dd5581a850e7b3ea1e98def0c2285221ac99a1a075b711c3315fa0af137b1de1d6becbb4a620c40e84fed0687ab8e7e3de45d6420d9dc4
|
7
|
+
data.tar.gz: 75487ca0f8b511f5c2905ba5f652f992559052fa8f1ef264272aa591f1ed1f5434db7f4a032ba2ca7e418fb7fd4e84391544ecafc7534cd55ef3ecbf5c65e168
|
@@ -1,42 +1,45 @@
|
|
1
1
|
require 'alephant/publisher/views'
|
2
|
-
require 'json'
|
3
2
|
require 'hashie'
|
4
3
|
|
5
|
-
module Alephant
|
6
|
-
module
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
4
|
+
module Alephant
|
5
|
+
module Publisher
|
6
|
+
module Views
|
7
|
+
module Base
|
8
|
+
def self.included base
|
9
|
+
base.send :include, InstanceMethods
|
10
|
+
base.extend ClassMethods
|
11
|
+
end
|
11
12
|
|
12
|
-
|
13
|
-
|
13
|
+
module InstanceMethods
|
14
|
+
attr_reader :data, :content_type, :base_path
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
def initialize(data = {})
|
17
|
+
@data = Hashie::Mash.new data
|
18
|
+
@base_path = self.class.base_path
|
18
19
|
|
19
|
-
|
20
|
-
|
20
|
+
setup
|
21
|
+
end
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
|
23
|
+
def to_h
|
24
|
+
whitelist.reduce({}) { |m,s| m.tap { |m| m[s] = self.send(s) } }
|
25
|
+
end
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
27
|
+
def setup; end
|
28
|
+
def whitelist; [] end
|
29
|
+
end
|
29
30
|
|
30
|
-
|
31
|
-
|
31
|
+
module ClassMethods
|
32
|
+
attr_accessor :base_path
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
|
34
|
+
def inherited(subclass)
|
35
|
+
current_dir = File.dirname(caller.first[/\/[^:]+/])
|
36
|
+
dir_path = Pathname.new(File.join(current_dir,'..')).realdirpath
|
36
37
|
|
37
|
-
|
38
|
+
subclass.base_path = dir_path.to_s
|
38
39
|
|
39
|
-
|
40
|
+
Alephant::Publisher::Views.register(subclass)
|
41
|
+
end
|
42
|
+
end
|
40
43
|
end
|
41
44
|
end
|
42
45
|
end
|
@@ -2,59 +2,62 @@ require 'alephant/publisher/views/base'
|
|
2
2
|
require 'mustache'
|
3
3
|
require 'i18n'
|
4
4
|
|
5
|
-
module Alephant
|
6
|
-
|
7
|
-
|
5
|
+
module Alephant
|
6
|
+
module Publisher
|
7
|
+
module Views
|
8
|
+
class Html < Mustache
|
9
|
+
include ::Alephant::Publisher::Views::Base
|
10
|
+
|
11
|
+
def setup
|
12
|
+
@content_type = "text/html"
|
13
|
+
load_translations_from base_path
|
14
|
+
end
|
15
|
+
|
16
|
+
def locale
|
17
|
+
:en
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def load_translations_from(base_path)
|
23
|
+
if I18n.load_path.empty?
|
24
|
+
I18n.config.enforce_available_locales = false
|
25
|
+
I18n.load_path = i18n_load_path_from(base_path)
|
26
|
+
I18n.backend.load_translations
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def i18n_load_path_from(base_path)
|
31
|
+
Dir[
|
32
|
+
File.join(
|
33
|
+
Pathname.new(base_path).parent,
|
34
|
+
'locale',
|
35
|
+
'*.yml')
|
36
|
+
]
|
37
|
+
.flatten
|
38
|
+
.uniq
|
39
|
+
end
|
40
|
+
|
41
|
+
def t(key, params = {})
|
42
|
+
I18n.locale = locale
|
43
|
+
prefix = /\/([^\/]+)\.mustache/.match(template_file)[1]
|
44
|
+
params.merge! :default => key unless params[:default]
|
45
|
+
translation = I18n.translate("#{prefix}.#{key}", params)
|
46
|
+
end
|
47
|
+
|
48
|
+
def template
|
49
|
+
@template_string ||= File.open(template_file).read
|
50
|
+
end
|
51
|
+
|
52
|
+
def template_name
|
53
|
+
Mustache.underscore(self.class.to_s).split('/').last
|
54
|
+
end
|
55
|
+
|
56
|
+
def template_file
|
57
|
+
File.join(base_path,'templates',"#{template_name}.#{template_extension}")
|
58
|
+
end
|
8
59
|
|
9
|
-
def setup
|
10
|
-
@content_type = "text/html"
|
11
|
-
load_translations_from base_path
|
12
|
-
end
|
13
|
-
|
14
|
-
def locale
|
15
|
-
:en
|
16
|
-
end
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
def load_translations_from(base_path)
|
21
|
-
if I18n.load_path.empty?
|
22
|
-
I18n.config.enforce_available_locales = false
|
23
|
-
I18n.load_path = i18n_load_path_from(base_path)
|
24
|
-
I18n.backend.load_translations
|
25
60
|
end
|
26
61
|
end
|
27
|
-
|
28
|
-
def i18n_load_path_from(base_path)
|
29
|
-
Dir[
|
30
|
-
File.join(
|
31
|
-
Pathname.new(base_path).parent,
|
32
|
-
'locale',
|
33
|
-
'*.yml')
|
34
|
-
]
|
35
|
-
.flatten
|
36
|
-
.uniq
|
37
|
-
end
|
38
|
-
|
39
|
-
def t(key, params = {})
|
40
|
-
I18n.locale = locale
|
41
|
-
prefix = /\/([^\/]+)\.mustache/.match(template_file)[1]
|
42
|
-
params.merge! :default => key unless params[:default]
|
43
|
-
translation = I18n.translate("#{prefix}.#{key}", params)
|
44
|
-
end
|
45
|
-
|
46
|
-
def template
|
47
|
-
@template_string ||= File.open(template_file).read
|
48
|
-
end
|
49
|
-
|
50
|
-
def template_name
|
51
|
-
Mustache.underscore(self.class.to_s).split('/').last
|
52
|
-
end
|
53
|
-
|
54
|
-
def template_file
|
55
|
-
File.join(base_path,'templates',"#{template_name}.#{template_extension}")
|
56
|
-
end
|
57
|
-
|
58
62
|
end
|
59
63
|
end
|
60
|
-
|
@@ -1,18 +1,21 @@
|
|
1
1
|
require 'alephant/publisher/views/base'
|
2
2
|
require 'json'
|
3
3
|
|
4
|
-
module Alephant
|
5
|
-
|
6
|
-
|
4
|
+
module Alephant
|
5
|
+
module Publisher
|
6
|
+
module Views
|
7
|
+
class Json
|
8
|
+
include ::Alephant::Publisher::Views::Base
|
7
9
|
|
8
|
-
|
9
|
-
|
10
|
-
|
10
|
+
def setup
|
11
|
+
@content_type = "application/json"
|
12
|
+
end
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
-
|
14
|
+
def render
|
15
|
+
JSON.generate(to_h)
|
16
|
+
end
|
15
17
|
|
18
|
+
end
|
19
|
+
end
|
16
20
|
end
|
17
21
|
end
|
18
|
-
|
data/lib/alephant/publisher.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alephant-publisher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Integralist
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|