wst 0.9.1 → 0.10.0

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: 1d4e39821ab781b82410d564e334910a830ea243
4
- data.tar.gz: e23a8193b48e32a9011fb36fb0f3f96c8ad94c8b
3
+ metadata.gz: a0f996c6d749a1111382813594a907eccac09559
4
+ data.tar.gz: f8b0e4f25d1bca482568cce4d58adeea6badb040
5
5
  SHA512:
6
- metadata.gz: 5df0d135f7cba7a499d7b5e6cb6206dd356a93a687e83839fe2d869a868c574ae139144920241f0646ce1fe6a3b6b24e549431a98ee8d97348b82d28c9f7ee01
7
- data.tar.gz: f52fe27732d41d984585f8d910c0a193878460c62de4399f73b22a553c12c62fd3cbce6c31856e5efe708b81797e59c7debf4990eb4a82689146cb0cef4b5fab
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='#{url_for(content, ext)}'>#{name}</a>"
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
- url_for_string content, ext
39
+ def url content, ext = 'html', prefix = false
40
+ url = if content.is_a? String
41
+ content
38
42
  else
39
- url_for_string content.url, ext
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
- engine = Haml::Engine.new partial_haml_content(opts[:partial]).raw_content
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
- default_path = File.join config['path'], '_layouts', "#{partial}.haml"
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wst
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yves Brissaud