alephant-publisher 0.6.3 → 0.6.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1e5634f22ebe808465e7d14556d052dddc5afbd3
4
- data.tar.gz: 265d58d561b42cc0148543761339905dfc68d2a2
3
+ metadata.gz: 9fe2812878ad4f51f2ac6a319f3815469be493a8
4
+ data.tar.gz: d8ab5c8158028eb611f02ee4d6a0b9a92ccdd40a
5
5
  SHA512:
6
- metadata.gz: 63e08ec5e1f1f576df406a7edb02a90267dc6cd05a94e6ea4f028376b6bc90e37b04c05beee6a42c77c10213b32235107952d40a7bcb4e910a289ff2784df3f1
7
- data.tar.gz: cc80de7fe8d6ac58674c81d7066b1d67e05f7e4b559396dbec6c784c2f03329b8703bf668df3557bde30052f6ca0fe474d0038c0a5d832d6c1306533fc702cb4
6
+ metadata.gz: b7b9cc3b1787c30fc4dd5581a850e7b3ea1e98def0c2285221ac99a1a075b711c3315fa0af137b1de1d6becbb4a620c40e84fed0687ab8e7e3de45d6420d9dc4
7
+ data.tar.gz: 75487ca0f8b511f5c2905ba5f652f992559052fa8f1ef264272aa591f1ed1f5434db7f4a032ba2ca7e418fb7fd4e84391544ecafc7534cd55ef3ecbf5c65e168
@@ -1,5 +1,5 @@
1
1
  module Alephant
2
2
  module Publisher
3
- VERSION = "0.6.3"
3
+ VERSION = "0.6.4"
4
4
  end
5
5
  end
@@ -1,42 +1,45 @@
1
1
  require 'alephant/publisher/views'
2
- require 'json'
3
2
  require 'hashie'
4
3
 
5
- module Alephant::Publisher::Views
6
- module Base
7
- def self.included base
8
- base.send :include, InstanceMethods
9
- base.extend ClassMethods
10
- end
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
- module InstanceMethods
13
- attr_reader :data, :content_type, :base_path
13
+ module InstanceMethods
14
+ attr_reader :data, :content_type, :base_path
14
15
 
15
- def initialize(data = {})
16
- @data = Hashie::Mash.new data
17
- @base_path = self.class.base_path
16
+ def initialize(data = {})
17
+ @data = Hashie::Mash.new data
18
+ @base_path = self.class.base_path
18
19
 
19
- setup
20
- end
20
+ setup
21
+ end
21
22
 
22
- def to_h
23
- whitelist.reduce({}) { |m,s| m.tap { |m| m[s] = self.send(s) } }
24
- end
23
+ def to_h
24
+ whitelist.reduce({}) { |m,s| m.tap { |m| m[s] = self.send(s) } }
25
+ end
25
26
 
26
- def setup; end
27
- def whitelist; [] end
28
- end
27
+ def setup; end
28
+ def whitelist; [] end
29
+ end
29
30
 
30
- module ClassMethods
31
- attr_accessor :base_path
31
+ module ClassMethods
32
+ attr_accessor :base_path
32
33
 
33
- def inherited(subclass)
34
- current_dir = File.dirname(caller.first[/\/[^:]+/])
35
- dir_path = Pathname.new(File.join(current_dir,'..')).realdirpath
34
+ def inherited(subclass)
35
+ current_dir = File.dirname(caller.first[/\/[^:]+/])
36
+ dir_path = Pathname.new(File.join(current_dir,'..')).realdirpath
36
37
 
37
- subclass.base_path = dir_path.to_s
38
+ subclass.base_path = dir_path.to_s
38
39
 
39
- Alephant::Publisher::Views.register(subclass)
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::Publisher::Views
6
- class Html < Mustache
7
- include Base
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::Publisher::Views
5
- class Json
6
- include Base
4
+ module Alephant
5
+ module Publisher
6
+ module Views
7
+ class Json
8
+ include ::Alephant::Publisher::Views::Base
7
9
 
8
- def setup
9
- @content_type = "application/json"
10
- end
10
+ def setup
11
+ @content_type = "application/json"
12
+ end
11
13
 
12
- def render
13
- JSON.generate(to_h)
14
- end
14
+ def render
15
+ JSON.generate(to_h)
16
+ end
15
17
 
18
+ end
19
+ end
16
20
  end
17
21
  end
18
-
@@ -1,6 +1,3 @@
1
- require 'alephant/publisher/views/html'
2
- require 'alephant/publisher/views/json'
3
-
4
1
  module Alephant
5
2
  module Publisher
6
3
  module Views
@@ -9,6 +9,7 @@ require 'alephant/support/aop'
9
9
  require 'alephant/publisher/processor'
10
10
  require 'alephant/publisher/views'
11
11
  require 'alephant/publisher/views/base'
12
+ require 'json'
12
13
 
13
14
  module Alephant
14
15
  module Publisher
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.3
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 00:00:00.000000000 Z
11
+ date: 2014-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler