wor 0.0.4 → 0.0.5
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/Gemfile.lock +1 -1
- data/lib/wor/collection.rb +48 -0
- data/lib/wor/collection_item.rb +34 -6
- data/lib/wor/configuration.rb +6 -0
- data/lib/wor/helpers.rb +10 -0
- data/lib/wor/localization.rb +73 -0
- data/lib/wor.rb +24 -46
- data/spec/rails_app/config/locales/wor.pt.yml +2 -1
- data/spec/rails_app/content/courses/{curso-teste.md → test.md} +0 -1
- data/spec/rails_app/content/pages/courses.md +8 -0
- data/spec/wor_spec.rb +82 -27
- data/wor.gemspec +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a3a97cac4c47daa5b8066be8e72cfecb6b120179
|
4
|
+
data.tar.gz: f8bf53bc4c0798c05e8ad543cf1922d994000321
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32ca962788a29ccb71eebe3afa297d82cce48e5962361172a657dc4fd4ddc52f4d0e87d3f9cb1edecd7c6c3cecc82b58cd3c702fbeb6e418eebe2950c5dbf79c
|
7
|
+
data.tar.gz: 7a335f27b49f245fa256cf6198bfc3cf370c04c3a7212713e111f5d87ec431bd7f34f8a1885a6db0c86a77241e14d1e203bb1ae0bafc0319e3eb819a0a8204f9
|
data/Gemfile.lock
CHANGED
data/lib/wor/collection.rb
CHANGED
@@ -2,6 +2,54 @@ module WOR
|
|
2
2
|
class Collection
|
3
3
|
attr_accessor :name
|
4
4
|
|
5
|
+
# Class Methods (Static)
|
6
|
+
class << self
|
7
|
+
def get_folder_name params
|
8
|
+
if (!WOR::Configuration::USE_LOCALIZATION)
|
9
|
+
return params[:collection_name]
|
10
|
+
end
|
11
|
+
|
12
|
+
locale_info = WOR::Localization.read_locale_file(params[:locale])
|
13
|
+
|
14
|
+
if (locale_info.nil?)
|
15
|
+
return params[:collection_name]
|
16
|
+
end
|
17
|
+
|
18
|
+
locale_info['paths'].each do | key, value |
|
19
|
+
if (value == params[:collection_name].to_s)
|
20
|
+
return key
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
return params[:collection_name]
|
25
|
+
end
|
26
|
+
|
27
|
+
def get_folder_name_by_path(params)
|
28
|
+
original_collection_name = WOR::Helpers.get_parent_directory_name params[:path]
|
29
|
+
return get_folder_name(locale: params[:locale], collection_name: original_collection_name)
|
30
|
+
end
|
31
|
+
|
32
|
+
def get_folder_url(params)
|
33
|
+
if (!WOR::Configuration::USE_LOCALIZATION)
|
34
|
+
return params[:collection_name]
|
35
|
+
end
|
36
|
+
|
37
|
+
locale_info = WOR::Localization.read_locale_file(params[:locale])
|
38
|
+
|
39
|
+
if (locale_info.nil?)
|
40
|
+
return params[:collection_name]
|
41
|
+
end
|
42
|
+
|
43
|
+
locale_info['paths'].each do | key, value |
|
44
|
+
if (key == params[:collection_name].to_s)
|
45
|
+
return value
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
return params[:collection_name]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
5
53
|
def initialize collection_name
|
6
54
|
@name = collection_name
|
7
55
|
end
|
data/lib/wor/collection_item.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
module WOR
|
2
2
|
class CollectionItem
|
3
|
-
attr_accessor :
|
3
|
+
attr_accessor :body, :layout, :locale, :collection_name, :name
|
4
4
|
|
5
5
|
def initialize path
|
6
|
-
self.path = path
|
7
6
|
self.body = Hash.new
|
8
7
|
self.layout = "application"
|
9
8
|
self.name = "Null"
|
@@ -13,15 +12,26 @@ module WOR
|
|
13
12
|
return
|
14
13
|
end
|
15
14
|
|
15
|
+
if (WOR::Configuration::USE_LOCALIZATION)
|
16
|
+
self.locale = WOR::Localization.get_locale
|
17
|
+
self.collection_name = WOR::Collection.get_folder_name_by_path(path: path, locale: self.locale)
|
18
|
+
else
|
19
|
+
self.collection_name = WOR::Collection.get_folder_name_by_path(path: path)
|
20
|
+
end
|
21
|
+
|
16
22
|
if (File.file?(path))
|
17
|
-
|
18
|
-
self.name = File.basename path, extn
|
19
|
-
create_custom_properties(self.path, true)
|
23
|
+
file_initialize path
|
20
24
|
else
|
21
|
-
directory_initialize
|
25
|
+
directory_initialize path
|
22
26
|
end
|
23
27
|
end
|
24
28
|
|
29
|
+
def file_initialize path
|
30
|
+
extn = File.extname path
|
31
|
+
self.name = File.basename path, extn
|
32
|
+
create_custom_properties(path, true)
|
33
|
+
end
|
34
|
+
|
25
35
|
def directory_initialize path
|
26
36
|
files = Dir.glob(path + "/*")
|
27
37
|
|
@@ -75,6 +85,24 @@ module WOR
|
|
75
85
|
self.body[language] = file_data
|
76
86
|
end
|
77
87
|
|
88
|
+
def url
|
89
|
+
if (self.collection_name == "pages")
|
90
|
+
translated_collection = ""
|
91
|
+
else
|
92
|
+
translated_collection = "/" + WOR::Localization.translate_path_to_language(path: self.collection_name, locale: self.locale)
|
93
|
+
end
|
94
|
+
|
95
|
+
if (self.name == "index")
|
96
|
+
translated_name = ""
|
97
|
+
else
|
98
|
+
translated_name = "/" + WOR::Localization.translate_path_to_language(path: self.name, locale: self.locale)
|
99
|
+
end
|
100
|
+
|
101
|
+
url = "/#{self.locale}#{translated_collection}#{translated_name}"
|
102
|
+
|
103
|
+
return url
|
104
|
+
end
|
105
|
+
|
78
106
|
private
|
79
107
|
def create_custom_properties file, get_body
|
80
108
|
results = File.read(file).match(/(---.+---)(.*)/m)
|
data/lib/wor/helpers.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
module WOR
|
2
|
+
class Localization
|
3
|
+
|
4
|
+
# Class Methods (Statics)
|
5
|
+
class << self
|
6
|
+
def translate_path_to_original params
|
7
|
+
if (!WOR::Configuration::USE_LOCALIZATION)
|
8
|
+
return params[:path]
|
9
|
+
end
|
10
|
+
|
11
|
+
locale_info = WOR::Localization.read_locale_file(params[:locale])
|
12
|
+
|
13
|
+
if (locale_info.nil?)
|
14
|
+
return params[:path]
|
15
|
+
end
|
16
|
+
|
17
|
+
locale_info['paths'].each do | key, value |
|
18
|
+
if (value == params[:path].to_s)
|
19
|
+
return key
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
return params[:path]
|
24
|
+
end
|
25
|
+
|
26
|
+
def translate_path_to_language params
|
27
|
+
if (!WOR::Configuration::USE_LOCALIZATION)
|
28
|
+
return params[:path]
|
29
|
+
end
|
30
|
+
|
31
|
+
locale_info = WOR::Localization.read_locale_file(params[:locale])
|
32
|
+
|
33
|
+
if (locale_info.nil?)
|
34
|
+
return params[:path]
|
35
|
+
end
|
36
|
+
|
37
|
+
locale_info['paths'].each do | key, value |
|
38
|
+
if (key == params[:path].to_s)
|
39
|
+
return value
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
return params[:path]
|
44
|
+
end
|
45
|
+
|
46
|
+
def get_locale
|
47
|
+
locale = I18n.locale
|
48
|
+
|
49
|
+
if (locale.nil?)
|
50
|
+
locale = Wor::Configuration::DEFAULT_LOCALE
|
51
|
+
end
|
52
|
+
|
53
|
+
return locale
|
54
|
+
end
|
55
|
+
|
56
|
+
def read_locale_file locale
|
57
|
+
require 'yaml'
|
58
|
+
|
59
|
+
path = "#{Rails.root}/config/locales/wor.#{locale}.yml"
|
60
|
+
|
61
|
+
locale_info = nil
|
62
|
+
|
63
|
+
begin
|
64
|
+
locale_info = YAML.load_file(path)
|
65
|
+
rescue
|
66
|
+
locale_info = nil
|
67
|
+
end
|
68
|
+
|
69
|
+
return locale_info
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
data/lib/wor.rb
CHANGED
@@ -3,61 +3,39 @@ require 'rails'
|
|
3
3
|
module WOR
|
4
4
|
autoload :Collection, 'wor/collection'
|
5
5
|
autoload :CollectionItem, 'wor/collection_item'
|
6
|
+
autoload :Configuration, 'wor/configuration'
|
7
|
+
autoload :Helpers, 'wor/helpers'
|
8
|
+
autoload :Localization, 'wor/localization'
|
6
9
|
|
7
10
|
class Core
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
11
|
+
# Class Methods (Static)
|
12
|
+
class << self
|
13
|
+
def find params
|
14
|
+
# Build path
|
15
|
+
path = "#{Rails.root}/content"
|
16
|
+
|
17
|
+
if (params[:locale].present?)
|
18
|
+
if (WOR::Configuration::DEFAULT_LOCALE == params[:locale].to_s)
|
19
|
+
path += "/#{params[:collection]}"
|
20
|
+
else
|
21
|
+
collection_name = params[:collection]
|
22
|
+
translated_collection_name = WOR::Collection.get_folder_name(locale: params[:locale], collection_name: collection_name)
|
23
|
+
path += "/#{params[:collection]}"
|
24
|
+
end
|
25
|
+
|
26
|
+
path += "/#{WOR::Localization.translate_path_to_original(path: params[:page_name], locale: params[:locale])}.md"
|
27
|
+
else
|
28
|
+
path += "/#{params[:page_name]}.md"
|
19
29
|
end
|
20
|
-
end
|
21
|
-
|
22
|
-
return target_item
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.get_collection params
|
26
|
-
folder_name = self.get_collection_folder_name(params[:locale], params[:collection])
|
27
|
-
|
28
|
-
return WOR::Collection.new folder_name
|
29
|
-
end
|
30
30
|
|
31
|
-
|
32
|
-
locale_info = self.read_locale_file(locale)
|
31
|
+
I18n.locale = params[:locale]
|
33
32
|
|
34
|
-
|
35
|
-
return collection_name
|
33
|
+
return CollectionItem.new path
|
36
34
|
end
|
37
35
|
|
38
|
-
|
39
|
-
if (value == collection_name)
|
40
|
-
return key
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
return collection_name
|
45
|
-
end
|
36
|
+
def build_path
|
46
37
|
|
47
|
-
def self.read_locale_file locale
|
48
|
-
require 'yaml'
|
49
|
-
|
50
|
-
path = "#{Rails.root}/config/locales/wor.#{locale}.yml"
|
51
|
-
|
52
|
-
locale_info = nil
|
53
|
-
|
54
|
-
begin
|
55
|
-
locale_info = YAML.load_file(path)
|
56
|
-
rescue
|
57
|
-
locale_info = nil
|
58
38
|
end
|
59
|
-
|
60
|
-
return locale_info
|
61
39
|
end
|
62
40
|
end
|
63
41
|
end
|
data/spec/wor_spec.rb
CHANGED
@@ -2,55 +2,110 @@ require 'wor'
|
|
2
2
|
require 'test_helper'
|
3
3
|
|
4
4
|
describe WOR::Core do
|
5
|
-
it '
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
it 'find' do
|
6
|
+
params = { collection: "pages", locale: "en", page_name: "index"}
|
7
|
+
target = WOR::Core.find(params)
|
8
|
+
|
9
|
+
expect(target.permalink).not_to be(nil)
|
9
10
|
end
|
10
11
|
|
11
|
-
it '
|
12
|
-
|
13
|
-
|
12
|
+
it 'find with basename' do
|
13
|
+
params = { collection: "cursos", locale: "pt", page_name: "teste"}
|
14
|
+
target = WOR::Core.find(params)
|
15
|
+
|
16
|
+
expect(target).not_to be(nil)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'find with basename without item have permalink on language' do
|
20
|
+
params = { collection: "courses", locale: "en", page_name: "test" }
|
21
|
+
target = WOR::Core.find(params)
|
22
|
+
|
23
|
+
expect(target.permalink).not_to be(nil)
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'get url of root in default language' do
|
27
|
+
params = { collection: "pages", locale: "en", page_name: "index" }
|
28
|
+
target = WOR::Core.find(params)
|
29
|
+
|
30
|
+
expect(target.url).to eq("/en")
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'get url of root in pt language' do
|
34
|
+
params = { collection: "pages", locale: "pt", page_name: "index" }
|
35
|
+
target = WOR::Core.find(params)
|
36
|
+
|
37
|
+
expect(target.url).to eq("/pt")
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'get url of page in default language' do
|
41
|
+
params = { collection: "pages", locale: "en", page_name: "courses" }
|
42
|
+
target = WOR::Core.find(params)
|
43
|
+
|
44
|
+
expect(target.url).to eq("/en/courses")
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'get url of page in pt language' do
|
48
|
+
params = { collection: "pages", locale: "pt", page_name: "cursos" }
|
49
|
+
target = WOR::Core.find(params)
|
50
|
+
|
51
|
+
expect(target.url).to eq("/pt/cursos")
|
14
52
|
end
|
53
|
+
end
|
15
54
|
|
16
|
-
|
17
|
-
|
18
|
-
|
55
|
+
describe WOR::Helpers do
|
56
|
+
it 'return parent directory of file' do
|
57
|
+
parent = WOR::Helpers.get_parent_directory_name "#{Rails.root}/content/courses/curso-teste.md"
|
58
|
+
expect(parent).to eq("courses")
|
19
59
|
end
|
60
|
+
end
|
20
61
|
|
21
|
-
|
22
|
-
|
23
|
-
|
62
|
+
describe WOR::Collection do
|
63
|
+
it 'return original collection name' do
|
64
|
+
locale = 'pt'
|
65
|
+
original_collection_name = WOR::Collection.get_folder_name(locale: locale, collection_name: 'cursos')
|
66
|
+
expect(original_collection_name).to eq("courses")
|
24
67
|
end
|
68
|
+
end
|
25
69
|
|
70
|
+
describe WOR::Localization do
|
26
71
|
it 'read locale file that exists' do
|
27
|
-
locale_file = WOR::
|
72
|
+
locale_file = WOR::Localization.read_locale_file('en')
|
28
73
|
expect(locale_file).not_to be(nil)
|
29
74
|
end
|
30
75
|
|
31
76
|
it 'read locale file that not exists' do
|
32
|
-
locale_file = WOR::
|
77
|
+
locale_file = WOR::Localization.read_locale_file('fr')
|
33
78
|
expect(locale_file).to be(nil)
|
34
79
|
end
|
35
80
|
|
36
|
-
|
37
|
-
|
38
|
-
target = WOR::Core.find(params)
|
81
|
+
it 'get translated url in default language' do
|
82
|
+
url = WOR::Localization.translate_path_to_language(path: "courses", locale: "en")
|
39
83
|
|
40
|
-
expect(
|
84
|
+
expect(url).to eq("courses")
|
41
85
|
end
|
42
86
|
|
43
|
-
it '
|
44
|
-
|
45
|
-
target = WOR::Core.find(params)
|
87
|
+
it 'get translated url in pt language' do
|
88
|
+
url = WOR::Localization.translate_path_to_language(path: "courses", locale: "pt")
|
46
89
|
|
47
|
-
expect(
|
90
|
+
expect(url).to eq("cursos")
|
48
91
|
end
|
92
|
+
end
|
49
93
|
|
50
|
-
|
51
|
-
|
52
|
-
|
94
|
+
describe WOR::CollectionItem do
|
95
|
+
it 'get url in default language' do
|
96
|
+
I18n.locale = 'en'
|
97
|
+
item = WOR::CollectionItem.new "#{Rails.root}/content/courses/test.md"
|
98
|
+
expect(item.url).to eql("/en/courses/test")
|
99
|
+
end
|
53
100
|
|
54
|
-
|
101
|
+
it 'get url in pt language' do
|
102
|
+
I18n.locale = 'pt'
|
103
|
+
item = WOR::CollectionItem.new "#{Rails.root}/content/courses/test.md"
|
104
|
+
expect(item.url).to eql("/pt/cursos/teste")
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'get permalink index in pt' do
|
108
|
+
item_index = WOR::CollectionItem.new "#{Rails.root}/content/pages/index.md"
|
109
|
+
expect(item_index.get_permalink("pt")).to eql("/")
|
55
110
|
end
|
56
111
|
end
|
data/wor.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rodrigo Vargas
|
@@ -49,6 +49,9 @@ files:
|
|
49
49
|
- lib/wor.rb
|
50
50
|
- lib/wor/collection.rb
|
51
51
|
- lib/wor/collection_item.rb
|
52
|
+
- lib/wor/configuration.rb
|
53
|
+
- lib/wor/helpers.rb
|
54
|
+
- lib/wor/localization.rb
|
52
55
|
- log/test.log
|
53
56
|
- spec/rails_app/Rakefile
|
54
57
|
- spec/rails_app/config.ru
|
@@ -60,7 +63,8 @@ files:
|
|
60
63
|
- spec/rails_app/config/environments/test.rb
|
61
64
|
- spec/rails_app/config/locales/wor.en.yml
|
62
65
|
- spec/rails_app/config/locales/wor.pt.yml
|
63
|
-
- spec/rails_app/content/courses/
|
66
|
+
- spec/rails_app/content/courses/test.md
|
67
|
+
- spec/rails_app/content/pages/courses.md
|
64
68
|
- spec/rails_app/content/pages/index.md
|
65
69
|
- spec/rails_app/log/test.log
|
66
70
|
- spec/test_helper.rb
|