wst 0.9.1 → 0.10.0
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 +4 -4
- data/lib/configuration.rb +14 -0
- data/lib/haml_helpers_wlt_extensions.rb +44 -11
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a0f996c6d749a1111382813594a907eccac09559
|
4
|
+
data.tar.gz: f8b0e4f25d1bca482568cce4d58adeea6badb040
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b84213a2e57858037a030bff6c71c2af0ec277d09f3703e9dfd3ae3bfe94ff1c6ccb2f26e20c06f40ecb2f55d2e3039a801a1a9fdec403fafed3516e21b6bd5
|
7
|
+
data.tar.gz: e694815ee6af8ce2df5a984aaf0b32a85e8d12db415138db071603183a8c4e3af50465454062b88346096cf1342efccc2ebfebcd99636f1515b0e00b628fcc5c
|
data/lib/configuration.rb
CHANGED
@@ -21,6 +21,7 @@ module Wst
|
|
21
21
|
def self.read_config location, local
|
22
22
|
Configuration.read_configuration location, local
|
23
23
|
Configuration.read_default_links
|
24
|
+
Configuration.read_translations
|
24
25
|
end
|
25
26
|
|
26
27
|
def self.read_configuration location, local
|
@@ -36,6 +37,15 @@ module Wst
|
|
36
37
|
@defaultLinks = if File.exists? self.links_file_path then "\n" + File.open(self.links_file_path, "r:utf-8").read else "" end
|
37
38
|
end
|
38
39
|
|
40
|
+
def self.read_translations
|
41
|
+
@config['translations'] = {}
|
42
|
+
self.translation_files.each do |file|
|
43
|
+
translation = YAML.load File.open(file, 'r:utf-8').read
|
44
|
+
lang = File.basename file, '.yaml'
|
45
|
+
@config['translations'][lang] = translation
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
39
49
|
def self.valid_location? location
|
40
50
|
return false unless File.exists? File.join location, "config.yaml"
|
41
51
|
return false unless File.directory? File.join location, "_posts"
|
@@ -47,5 +57,9 @@ module Wst
|
|
47
57
|
def self.links_file_path
|
48
58
|
File.join config['path'], "links.md"
|
49
59
|
end
|
60
|
+
|
61
|
+
def self.translation_files
|
62
|
+
Dir.glob File.join config['path'], "_translations", "**.yaml"
|
63
|
+
end
|
50
64
|
end
|
51
65
|
end
|
@@ -13,7 +13,11 @@ module Haml
|
|
13
13
|
include Wst::Configuration
|
14
14
|
|
15
15
|
def link_to name, content, ext = 'html'
|
16
|
-
"<a href='#{
|
16
|
+
"<a href='#{url(content, ext)}'>#{name}</a>"
|
17
|
+
end
|
18
|
+
|
19
|
+
def link_to_p name, content, ext = 'html'
|
20
|
+
"<a href='#{url_p(content, ext)}'>#{name}</a>"
|
17
21
|
end
|
18
22
|
|
19
23
|
#def link_to_if condition, name, content, ext = 'html'
|
@@ -32,16 +36,26 @@ module Haml
|
|
32
36
|
# end
|
33
37
|
#end
|
34
38
|
|
35
|
-
def url content, ext = 'html'
|
36
|
-
if content.is_a? String
|
37
|
-
|
39
|
+
def url content, ext = 'html', prefix = false
|
40
|
+
url = if content.is_a? String
|
41
|
+
content
|
38
42
|
else
|
39
|
-
|
43
|
+
content.url
|
40
44
|
end
|
45
|
+
url_for_string url, ext, prefix
|
46
|
+
end
|
47
|
+
|
48
|
+
def url_p content, ext = 'html'
|
49
|
+
url content, ext, true
|
41
50
|
end
|
42
51
|
|
43
52
|
def render opts = {}
|
44
|
-
|
53
|
+
content = unless opts[:partial].nil?
|
54
|
+
partial_haml_content(opts[:partial], false)
|
55
|
+
else
|
56
|
+
partial_haml_content(opts[:partial_p], true)
|
57
|
+
end
|
58
|
+
engine = Haml::Engine.new content.raw_content
|
45
59
|
engine.render self
|
46
60
|
end
|
47
61
|
|
@@ -62,21 +76,40 @@ module Haml
|
|
62
76
|
end
|
63
77
|
end
|
64
78
|
|
79
|
+
def tr key, lang = nil
|
80
|
+
l = if lang.nil?
|
81
|
+
if content.prefix?
|
82
|
+
content.prefix
|
83
|
+
else
|
84
|
+
'default'
|
85
|
+
end
|
86
|
+
else
|
87
|
+
lang
|
88
|
+
end
|
89
|
+
if config['translations'].has_key?(l) && config['translations'][l].has_key?(key)
|
90
|
+
config['translations'][l][key]
|
91
|
+
else
|
92
|
+
key
|
93
|
+
end
|
94
|
+
end
|
65
95
|
|
66
96
|
private
|
67
97
|
|
68
|
-
def partial_path partial
|
69
|
-
|
98
|
+
def partial_path partial, prefix
|
99
|
+
p = "#{partial}.haml"
|
100
|
+
p = File.join(content.prefix, p) if prefix && content.prefix?
|
101
|
+
default_path = File.join config['path'], '_layouts', p
|
70
102
|
File.join File.dirname(default_path), "_#{File.basename(default_path)}"
|
71
103
|
end
|
72
104
|
|
73
|
-
def partial_haml_content partial
|
74
|
-
Wst::HamlContent.new partial_path(partial), content
|
105
|
+
def partial_haml_content partial, prefix
|
106
|
+
Wst::HamlContent.new partial_path(partial, prefix), content
|
75
107
|
end
|
76
108
|
|
77
|
-
def url_for_string url, ext
|
109
|
+
def url_for_string url, ext, prefix
|
78
110
|
path = url
|
79
111
|
path += ".#{ext}" if !url.empty? && File.extname(url).empty?
|
112
|
+
path = "#{content.prefix}/#{path}" if prefix && content.prefix?
|
80
113
|
"#{config['site_url']}/#{path}"
|
81
114
|
end
|
82
115
|
end
|