bobkit 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 026b002977ac0ef09bb4a46f6d6a50b05fabab6f
4
- data.tar.gz: 449e2f8ff40f0b8fc38cf9a808a49c54fcc72235
3
+ metadata.gz: 13c8f2ec6ec081beb417ccb392b47539caf923ef
4
+ data.tar.gz: 67851f24c8ed1e80d2851079a7680d1cbc90b5b2
5
5
  SHA512:
6
- metadata.gz: 5851936138b638b507bdf382a6d8a2a467c4e7f45a5b7666fcdc5065015745f744ab41c610656e708b9de4a842d169c79bd472f185657c1c4904d012569b8178
7
- data.tar.gz: 3d309f88de78e6cf58dc521f3c6d7d99b239860f0f2ac47b9bc1ec3c43d46131b3372aee514767a8e34556e4111a9ccda8c14da6db6fcf36cf23faca29512b4b
6
+ metadata.gz: ed328b74351587d7e0320310b4a4b52cb1985f22d6a0c76174167a051df3cb9f21c2b1d7094ad171bb24f874ed0f3341c8758ef34990af08cb093727ece3f30f
7
+ data.tar.gz: c0140b94f48370f96b621b140b1713c569d8469c805f639a43cb957d313ffdf59317bb6103ca570b3a0a51e57ed97b4b9306737eb55e7f19954fb573be0655ef
data/README.md CHANGED
@@ -19,6 +19,7 @@ The design intentions were:
19
19
  - To be packaged as a library, and not a command line tool.
20
20
  - To provide sensible default locations that are easily overridable.
21
21
  - To add `render` and `layout` support to Slim (Rails-like).
22
+ - To add i18n support to Slim (Rails-like).
22
23
  - To add `@import 'globbing/*'` support to SCSS (Rails-like).
23
24
 
24
25
  ---
@@ -89,6 +90,9 @@ layouts_folder 'my_layouts'
89
90
  # Location of the source SCSS files. Default: "styles"
90
91
  styles_folder 'styles'
91
92
 
93
+ # Location of locale configuration files. Default: "locales"
94
+ locales_folder 'locales'
95
+
92
96
  # Output location. Default: "output"
93
97
  output_folder 'site'
94
98
 
@@ -133,6 +137,9 @@ html = render 'user', layout: 'default', email: 'bob@kit.com'
133
137
  render 'user', layout: 'default', email: 'bob@kit.com', output: 'bob'
134
138
  ```
135
139
 
140
+ In addition, you can call `= render 'template'` from inside a slim
141
+ template.
142
+
136
143
 
137
144
  ### SCSS
138
145
 
@@ -169,6 +176,18 @@ copy_asset 'presskit.zip'
169
176
  copy_asset 'images'
170
177
  ```
171
178
 
179
+ ### Internationalization (I18n)
180
+
181
+ Bobkit supports these i18n features:
182
+
183
+ - Set the folder for your localization files with `locales_folder`
184
+ (default: 'locales').
185
+ - You can call `= t('common.hello')` from a slim template.
186
+ - You can call `= l(Time.now)` from a slim template.
187
+ - Any call to `render 'template_name'` will first look for a localized
188
+ version of the file (`template_name.en.slim`) and will use it if found.
189
+ Otherwise, it will use the unlozalized filename (`template_name.slim`).
190
+
172
191
 
173
192
  ### Low level file and folder helpers
174
193
 
@@ -0,0 +1,25 @@
1
+ module Bobkit
2
+ module I18nBridge
3
+ include I18nMixin
4
+
5
+ def locale(language=nil)
6
+ I18nHandler.instance.locale language if language
7
+ I18n.locale
8
+ end
9
+
10
+ class I18nHandler
11
+ include Singleton
12
+ include LocationOptions
13
+
14
+ def initialize
15
+ I18n.load_path = Dir["#{locales_folder}/**/*.yml"]
16
+ I18n.backend.load_translations
17
+ end
18
+
19
+ def locale(language)
20
+ I18n.locale = language
21
+ end
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,11 @@
1
+ module Bobkit
2
+ module I18nMixin
3
+ def t(*args)
4
+ I18n.t *args
5
+ end
6
+
7
+ def l(*args)
8
+ I18n.l *args
9
+ end
10
+ end
11
+ end
@@ -37,5 +37,9 @@ module Bobkit
37
37
  def assets_output_folder(path=nil)
38
38
  setopt :assets_output_folder, path, "#{output_folder}/assets"
39
39
  end
40
+
41
+ def locales_folder(path=nil)
42
+ setopt :locales_folder, path, "locales"
43
+ end
40
44
  end
41
45
  end
@@ -1,19 +1,31 @@
1
1
  module Bobkit
2
2
  module OptionsBase
3
3
  def use_defaults
4
- @@options = {}
4
+ OptionsHandler.instance.options = {}
5
5
  end
6
6
 
7
- protected
8
-
9
- def setopt(key, value=nil, default=nil)
10
- options[key] = value if value
11
- options[key] ||= default
12
- options[key]
7
+ def setopt(*args)
8
+ OptionsHandler.instance.setopt *args
13
9
  end
14
10
 
15
11
  def options
16
- @@options ||= {}
12
+ OptionsHandler.instance.options
13
+ end
14
+
15
+ class OptionsHandler
16
+ include Singleton
17
+
18
+ attr_accessor :options
19
+
20
+ def initialize
21
+ @options = {}
22
+ end
23
+
24
+ def setopt(key, value=nil, default=nil)
25
+ options[key] = value if value
26
+ options[key] ||= default
27
+ options[key]
28
+ end
17
29
  end
18
30
  end
19
31
  end
@@ -5,9 +5,6 @@ module Bobkit
5
5
  end
6
6
  alias_method :sass_options, :scss_options
7
7
 
8
-
9
- protected
10
-
11
8
  def scss_defaults
12
9
  { cache: true, syntax: :scss, style: :nested,
13
10
  load_paths: [styles_folder] }
data/lib/bobkit/scope.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  module Bobkit
2
2
  class Scope
3
3
  include SlimBridge
4
+ include I18nMixin
4
5
 
5
6
  def initialize(scope=nil)
6
7
  @scope = scope || {}
@@ -1,25 +1,50 @@
1
1
  module Bobkit
2
2
  module SlimBridge
3
- include FileHelpers
4
- include SlimOptions
5
- include LocationOptions
6
- include ScopeOptions
7
-
8
- def render(options={}, extra_options={})
9
- options = { partial: options }.merge(extra_options) if options.is_a? String
10
- partial = options.delete :partial
11
- layout = options.delete :layout
12
- output = options.delete :output
13
-
14
- context = options.empty? ? scope : options
15
- if context.is_a? Hash or !context
16
- context = Scope.new context
3
+ def render(*args)
4
+ SlimHandler.instance.render *args
5
+ end
6
+
7
+ class SlimHandler
8
+ include Singleton
9
+ include FileHelpers
10
+ include SlimOptions
11
+ include LocationOptions
12
+ include ScopeOptions
13
+ include I18nBridge
14
+
15
+ def render(options={}, extra_options={})
16
+ options = { partial: options }.merge(extra_options) if options.is_a? String
17
+ partial = options.delete :partial
18
+ layout = options.delete :layout
19
+ output = options.delete :output
20
+
21
+ context = options.empty? ? scope : options
22
+ if context.is_a? Hash or !context
23
+ context = Scope.new context
24
+ end
25
+
26
+ content = Slim::Template.new(partial_filename(partial), slim_options).render(context)
27
+ content = Slim::Template.new(layout_filename(layout), slim_options).render(context) { content } if layout
28
+ create_file "#{output_folder}/#{output}.html", content if output
29
+ content
17
30
  end
18
31
 
19
- content = Slim::Template.new("#{templates_folder}/#{partial}.slim", slim_options).render(context)
20
- content = Slim::Template.new("#{layouts_folder}/#{layout}.slim", slim_options).render(context) { content } if layout
21
- create_file "#{output_folder}/#{output}.html", content if output
22
- content
32
+ private
33
+
34
+ def partial_filename(partial)
35
+ localized_template templates_folder, partial
36
+ end
37
+
38
+ def layout_filename(layout)
39
+ localized_template layouts_folder, layout
40
+ end
41
+
42
+ def localized_template(folder, basename)
43
+ preferred = "#{folder}/#{basename}.#{locale}.slim"
44
+ return preferred if File.exist? preferred
45
+ "#{folder}/#{basename}.slim"
46
+ end
23
47
  end
48
+
24
49
  end
25
- end
50
+ end
@@ -4,8 +4,6 @@ module Bobkit
4
4
  setopt :slim_options, options, slim_defaults
5
5
  end
6
6
 
7
- protected
8
-
9
7
  def slim_defaults
10
8
  { pretty: true, disable_escape: true }
11
9
  end
data/lib/bobkit/tasks.rb CHANGED
@@ -5,6 +5,7 @@ module Bobkit
5
5
  include SassBridge
6
6
  include SlimBridge
7
7
  include CoffeeBridge
8
+ include I18nBridge
8
9
  include SlimOptions
9
10
  include SassOptions
10
11
  include ScopeOptions
@@ -1,3 +1,3 @@
1
1
  module Bobkit
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -1,27 +1,41 @@
1
1
  module Bobkit
2
2
  module Watcher
3
- def watch(paths=nil, &block)
3
+ def watch(*args)
4
4
  # :nocov:
5
- @paths = paths
6
- filewatcher.watch &block
5
+ FileWatcherHandler.instance.watch *args
7
6
  # :nocov:
8
7
  end
9
8
 
10
9
  def filewatcher
11
- FileWatcher.new(paths)
10
+ FileWatcherHandler.instance.filewatcher
12
11
  end
13
12
 
14
- protected
13
+ class FileWatcherHandler
14
+ include Singleton
15
+ include LocationOptions
15
16
 
16
- def paths
17
- @paths ||= all_input_paths
18
- end
17
+ def watch(paths=nil, &block)
18
+ # :nocov:
19
+ @paths = paths
20
+ filewatcher.watch &block
21
+ # :nocov:
22
+ end
23
+
24
+ def filewatcher
25
+ FileWatcher.new(paths)
26
+ end
27
+
28
+ protected
29
+
30
+ def paths
31
+ @paths ||= all_input_paths
32
+ end
33
+
34
+ def all_input_paths
35
+ [ templates_folder, layouts_folder, styles_folder,
36
+ coffee_folder, assets_folder, locales_folder ]
37
+ end
19
38
 
20
- def all_input_paths
21
- [ templates_folder, layouts_folder, styles_folder,
22
- coffee_folder, assets_folder ]
23
39
  end
24
40
  end
25
41
  end
26
-
27
-
data/lib/bobkit.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'i18n'
1
2
  require 'fileutils'
2
3
  require 'sass'
3
4
  require 'sass-globbing'
@@ -8,6 +9,8 @@ require 'filewatcher'
8
9
  require 'bobkit/options_base'
9
10
  require 'bobkit/location_options'
10
11
  require 'bobkit/file_helpers'
12
+ require 'bobkit/i18n_mixin'
13
+ require 'bobkit/i18n_bridge'
11
14
  require 'bobkit/scope_options'
12
15
  require 'bobkit/sass_options'
13
16
  require 'bobkit/sass_bridge'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bobkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-18 00:00:00.000000000 Z
11
+ date: 2016-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: slim
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '2.4'
69
+ - !ruby/object:Gem::Dependency
70
+ name: i18n
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.7'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.7'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: filewatcher
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -133,6 +147,8 @@ files:
133
147
  - lib/bobkit/assets.rb
134
148
  - lib/bobkit/coffee_bridge.rb
135
149
  - lib/bobkit/file_helpers.rb
150
+ - lib/bobkit/i18n_bridge.rb
151
+ - lib/bobkit/i18n_mixin.rb
136
152
  - lib/bobkit/location_options.rb
137
153
  - lib/bobkit/options_base.rb
138
154
  - lib/bobkit/sass_bridge.rb