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 +4 -4
- data/README.md +19 -0
- data/lib/bobkit/i18n_bridge.rb +25 -0
- data/lib/bobkit/i18n_mixin.rb +11 -0
- data/lib/bobkit/location_options.rb +4 -0
- data/lib/bobkit/options_base.rb +20 -8
- data/lib/bobkit/sass_options.rb +0 -3
- data/lib/bobkit/scope.rb +1 -0
- data/lib/bobkit/slim_bridge.rb +44 -19
- data/lib/bobkit/slim_options.rb +0 -2
- data/lib/bobkit/tasks.rb +1 -0
- data/lib/bobkit/version.rb +1 -1
- data/lib/bobkit/watcher.rb +27 -13
- data/lib/bobkit.rb +3 -0
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 13c8f2ec6ec081beb417ccb392b47539caf923ef
|
4
|
+
data.tar.gz: 67851f24c8ed1e80d2851079a7680d1cbc90b5b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/lib/bobkit/options_base.rb
CHANGED
@@ -1,19 +1,31 @@
|
|
1
1
|
module Bobkit
|
2
2
|
module OptionsBase
|
3
3
|
def use_defaults
|
4
|
-
|
4
|
+
OptionsHandler.instance.options = {}
|
5
5
|
end
|
6
6
|
|
7
|
-
|
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
|
-
|
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
|
data/lib/bobkit/sass_options.rb
CHANGED
data/lib/bobkit/scope.rb
CHANGED
data/lib/bobkit/slim_bridge.rb
CHANGED
@@ -1,25 +1,50 @@
|
|
1
1
|
module Bobkit
|
2
2
|
module SlimBridge
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
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
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
data/lib/bobkit/slim_options.rb
CHANGED
data/lib/bobkit/tasks.rb
CHANGED
data/lib/bobkit/version.rb
CHANGED
data/lib/bobkit/watcher.rb
CHANGED
@@ -1,27 +1,41 @@
|
|
1
1
|
module Bobkit
|
2
2
|
module Watcher
|
3
|
-
def watch(
|
3
|
+
def watch(*args)
|
4
4
|
# :nocov:
|
5
|
-
|
6
|
-
filewatcher.watch &block
|
5
|
+
FileWatcherHandler.instance.watch *args
|
7
6
|
# :nocov:
|
8
7
|
end
|
9
8
|
|
10
9
|
def filewatcher
|
11
|
-
|
10
|
+
FileWatcherHandler.instance.filewatcher
|
12
11
|
end
|
13
12
|
|
14
|
-
|
13
|
+
class FileWatcherHandler
|
14
|
+
include Singleton
|
15
|
+
include LocationOptions
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
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.
|
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-
|
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
|