rpictogrify 0.4.0 → 0.5.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/README.md +12 -9
- data/lib/rpictogrify/configuration.rb +8 -1
- data/lib/rpictogrify/theme.rb +17 -0
- data/lib/rpictogrify/themes/base.rb +14 -12
- data/lib/rpictogrify/version.rb +1 -1
- data/lib/rpictogrify.rb +5 -1
- data/spec/rpictogrify_spec.rb +28 -4
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 16f8ae00a030fcb82258a5885dda4f0de316b4e1d3ea98c0c32369ad6baf0f7c
|
4
|
+
data.tar.gz: 000f34d1b9d95c2ab8eaec9b3da7b859c01e120efa8ec5c18b9b7dc2dcb9ccfc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07cb42697c11d430ac62712e15cc21f5d761b2150d04e63c4b6dc1c80d8e742c4e3298d3c07f68e285777741676db21db4b3446e3e744a1df6b547337bfd086b
|
7
|
+
data.tar.gz: 8cf24261df62a257b1648348c7d6103a21029ecb61321b28572ed7102b003dea3327a1ba02df719512e2d888cbe9034b127e4113c2d0de3680312df4fa470f52
|
data/README.md
CHANGED
@@ -36,14 +36,17 @@ Rpictogrify.configure do
|
|
36
36
|
self.theme = :monsters
|
37
37
|
# pictogram directory. default is 'public/system'
|
38
38
|
self.base_path = 'public/system'
|
39
|
+
# register a custome theme with assets. assets see assets/themes
|
40
|
+
self.register_theme :custom, assets_path: 'vendor/assets/rpictogrify/themes/custom'
|
39
41
|
end
|
40
42
|
```
|
41
43
|
|
42
44
|
## Usage
|
43
45
|
|
44
46
|
```ruby
|
45
|
-
Rpictogrify.generate 'jim.cheung' #=> 'public/system/rpictogrify/1/monsters/
|
46
|
-
Rpictogrify.generate 'jim.cheung', theme: :avataars_male #=> 'public/system/rpictogrify/1/avataars_male/
|
47
|
+
Rpictogrify.generate 'jim.cheung' #=> 'public/system/rpictogrify/1/monsters/1313467160.svg'
|
48
|
+
Rpictogrify.generate 'jim.cheung', theme: :avataars_male #=> 'public/system/rpictogrify/1/avataars_male/1313467160.svg'
|
49
|
+
Rpictogrify.generate 'jim.cheung', theme: :custom #=> 'public/system/rpictogrify/1/custom/1313467160.svg', use custom theme
|
47
50
|
```
|
48
51
|
|
49
52
|
### Controller / View
|
@@ -57,10 +60,10 @@ include Rpictogrify::Helper
|
|
57
60
|
Then you can use the following methods in views.
|
58
61
|
|
59
62
|
```ruby
|
60
|
-
rpictogrify_for('jim', theme: :monsters) #=> 'public/system/rpictogrify/1/monsters/
|
61
|
-
rpictogrify_url('jim') #=> '/system/rpictogrify/1/monsters/
|
62
|
-
rpictogrify_tag('jim', html: {class: :avatar}) #=> '<img class="avatar" src="/system/rpictogrify/1/monsters/
|
63
|
-
rpictogrify_url_for('public/system/rpictogrify/1/monsters/
|
63
|
+
rpictogrify_for('jim', theme: :monsters) #=> 'public/system/rpictogrify/1/monsters/1313467160.svg'
|
64
|
+
rpictogrify_url('jim') #=> '/system/rpictogrify/1/monsters/1313467160.svg'
|
65
|
+
rpictogrify_tag('jim', html: {class: :avatar}) #=> '<img class="avatar" src="/system/rpictogrify/1/monsters/1313467160.svg" alt="jim" />'
|
66
|
+
rpictogrify_url_for('public/system/rpictogrify/1/monsters/1313467160.svg') #=> '/system/rpictogrify/1/monsters/1313467160.svg'
|
64
67
|
```
|
65
68
|
|
66
69
|
### Model
|
@@ -79,8 +82,8 @@ end
|
|
79
82
|
Then you have the following methods in user
|
80
83
|
|
81
84
|
```ruby
|
82
|
-
@user.rpictogrify_path #=> 'public/system/rpictogrify/1/monsters/
|
83
|
-
@user.rpictogrify_url #=> '/system/rpictogrify/1/monsters/
|
85
|
+
@user.rpictogrify_path #=> 'public/system/rpictogrify/1/monsters/1313467160.svg'
|
86
|
+
@user.rpictogrify_url #=> '/system/rpictogrify/1/monsters/1313467160.svg'
|
84
87
|
```
|
85
88
|
|
86
89
|
## Contributing
|
@@ -96,4 +99,4 @@ Please write unit test with your code if necessary.
|
|
96
99
|
|
97
100
|
## License
|
98
101
|
|
99
|
-
The gem is available as open source under the terms of the [MIT License](MIT-LICENSE).
|
102
|
+
The gem is available as open source under the terms of the [MIT License](MIT-LICENSE).
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'rpictogrify/theme'
|
4
|
+
|
3
5
|
module Rpictogrify
|
4
6
|
class Configuration
|
5
7
|
# default theme, one of these themes: avataars_female, avataars_male, male_flat, monsters. default is :monsters
|
@@ -13,5 +15,10 @@ module Rpictogrify
|
|
13
15
|
|
14
16
|
@base_path = 'public/system'
|
15
17
|
end
|
18
|
+
|
19
|
+
# register a custome theme with assets. assets see assets/themes.
|
20
|
+
def register_theme(ident, assets_path:)
|
21
|
+
Rpictogrify::Theme.register(ident, assets_path: assets_path)
|
22
|
+
end
|
16
23
|
end
|
17
|
-
end
|
24
|
+
end
|
data/lib/rpictogrify/theme.rb
CHANGED
@@ -15,6 +15,23 @@ module Rpictogrify
|
|
15
15
|
rescue NameError
|
16
16
|
raise ArgumentError.new('The ident argument must be one of themes: avataars_female, avataars_male, male_flat, monsters')
|
17
17
|
end
|
18
|
+
|
19
|
+
def register(ident, assets_path:)
|
20
|
+
define_class_context = ->(binding) do
|
21
|
+
@@assets_path = assets_path
|
22
|
+
def assets_path
|
23
|
+
Pathname.new(@@assets_path)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
theme_name = Rpictogrify::Inflector.camelize(ident.to_s)
|
28
|
+
theme_class = "Rpictogrify::Themes::#{theme_name}"
|
29
|
+
if Object.const_defined?(theme_class)
|
30
|
+
Object.const_get(theme_class).class_eval(&define_class_context)
|
31
|
+
else
|
32
|
+
Rpictogrify::Themes.const_set(theme_name, Class.new(Rpictogrify::Themes::Base, &define_class_context))
|
33
|
+
end
|
34
|
+
end
|
18
35
|
end
|
19
36
|
end
|
20
37
|
end
|
@@ -10,14 +10,12 @@ module Rpictogrify
|
|
10
10
|
include Singleton
|
11
11
|
extend SingleForwardable
|
12
12
|
|
13
|
-
attr_reader :mapping, :resource, :ident
|
14
|
-
def_delegators :instance, :mapping, :resource, :ident,
|
13
|
+
attr_reader :mapping, :resource, :ident, :assets_path
|
14
|
+
def_delegators :instance, :mapping, :resource, :ident, :assets_path,
|
15
15
|
:width, :height, :shapes, :colors, :symbol
|
16
16
|
|
17
17
|
def initialize
|
18
|
-
@ident
|
19
|
-
@mapping = parse_mapping
|
20
|
-
@resource = parse_resource
|
18
|
+
@ident = get_ident
|
21
19
|
end
|
22
20
|
|
23
21
|
def width
|
@@ -40,18 +38,22 @@ module Rpictogrify
|
|
40
38
|
resource.at_xpath("//*[@id='#{id}']")
|
41
39
|
end
|
42
40
|
|
43
|
-
|
41
|
+
def assets_path
|
42
|
+
Rpictogrify.themes_assets_path.join(ident)
|
43
|
+
end
|
44
44
|
|
45
|
-
def
|
46
|
-
|
45
|
+
def mapping
|
46
|
+
@mapping ||= JSON.parse(File.read(assets_path.join('mapping.json')))
|
47
47
|
end
|
48
48
|
|
49
|
-
def
|
50
|
-
|
49
|
+
def resource
|
50
|
+
@resource ||= Nokogiri.XML(File.read(assets_path.join('resource.svg')))
|
51
51
|
end
|
52
52
|
|
53
|
-
|
54
|
-
|
53
|
+
private
|
54
|
+
|
55
|
+
def get_ident
|
56
|
+
Rpictogrify::Inflector.underscore(self.class.name).split('/').last
|
55
57
|
end
|
56
58
|
|
57
59
|
def view_box
|
data/lib/rpictogrify/version.rb
CHANGED
data/lib/rpictogrify.rb
CHANGED
@@ -24,6 +24,10 @@ module Rpictogrify
|
|
24
24
|
@config ||= Configuration.new
|
25
25
|
end
|
26
26
|
|
27
|
+
def reset_config
|
28
|
+
@config = nil
|
29
|
+
end
|
30
|
+
|
27
31
|
def configure(&block)
|
28
32
|
config.instance_exec(&block)
|
29
33
|
end
|
@@ -44,4 +48,4 @@ module Rpictogrify
|
|
44
48
|
path.to_s.sub('public/', '/')
|
45
49
|
end
|
46
50
|
end
|
47
|
-
end
|
51
|
+
end
|
data/spec/rpictogrify_spec.rb
CHANGED
@@ -2,6 +2,10 @@ require 'spec_helper'
|
|
2
2
|
require 'rpictogrify'
|
3
3
|
|
4
4
|
describe Rpictogrify do
|
5
|
+
after do
|
6
|
+
Rpictogrify.reset_config
|
7
|
+
end
|
8
|
+
|
5
9
|
context 'configure' do
|
6
10
|
it 'load default config' do
|
7
11
|
expect(Rpictogrify.config.theme).to eq(:monsters)
|
@@ -16,11 +20,27 @@ describe Rpictogrify do
|
|
16
20
|
|
17
21
|
expect(Rpictogrify.config.theme).to eq(:avataars_female)
|
18
22
|
expect(Rpictogrify.config.base_path).to eq('public')
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'register theme' do
|
26
|
+
custom_theme_assets_path = 'vendor/assets/rpictogrify/themes/custom'
|
27
|
+
expect(defined?(Rpictogrify::Themes::Custom)).to be_falsy
|
28
|
+
|
29
|
+
Rpictogrify.configure do
|
30
|
+
self.theme = :custom
|
31
|
+
self.register_theme :custom, assets_path: custom_theme_assets_path
|
32
|
+
end
|
33
|
+
|
34
|
+
expect(defined?(Rpictogrify::Themes::Custom)).to be_truthy
|
35
|
+
expect(Rpictogrify::Themes::Custom.superclass).to eq Rpictogrify::Themes::Base
|
36
|
+
expect(Rpictogrify::Themes::Custom.assets_path).to eq Pathname.new(custom_theme_assets_path)
|
37
|
+
expect(Rpictogrify.config.theme).to eq(:custom)
|
19
38
|
|
20
39
|
Rpictogrify.configure do
|
21
|
-
self.
|
22
|
-
self.base_path = 'public/system'
|
40
|
+
self.register_theme :monsters, assets_path: Pathname.new(custom_theme_assets_path)
|
23
41
|
end
|
42
|
+
expect(Rpictogrify::Themes::Monsters.assets_path).to eq Pathname.new(custom_theme_assets_path)
|
43
|
+
expect(Rpictogrify::Themes::Monsters.superclass).to eq Rpictogrify::Themes::Base
|
24
44
|
end
|
25
45
|
end
|
26
46
|
|
@@ -44,11 +64,15 @@ describe Rpictogrify do
|
|
44
64
|
path = Rpictogrify.generate 'jim.cheung'
|
45
65
|
expect(path).to include('avataars_female')
|
46
66
|
expect(path).to include('public/custom')
|
67
|
+
end
|
47
68
|
|
69
|
+
it 'return pictogram path with custom theme' do
|
48
70
|
Rpictogrify.configure do
|
49
|
-
self.
|
50
|
-
self.base_path = 'public/system'
|
71
|
+
self.register_theme :custom, assets_path: 'assets/themes/male_flat'
|
51
72
|
end
|
73
|
+
|
74
|
+
path = Rpictogrify.generate 'jim.cheung', theme: :custom
|
75
|
+
expect(path).to include('custom')
|
52
76
|
end
|
53
77
|
end
|
54
78
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rpictogrify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jim Cheung
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-07-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -104,10 +104,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
104
|
- !ruby/object:Gem::Version
|
105
105
|
version: '0'
|
106
106
|
requirements: []
|
107
|
-
rubygems_version: 3.
|
107
|
+
rubygems_version: 3.2.3
|
108
108
|
signing_key:
|
109
109
|
specification_version: 4
|
110
110
|
summary: Ruby version of the pictogrify to generate unique pictograms
|
111
111
|
test_files:
|
112
|
-
- spec/spec_helper.rb
|
113
112
|
- spec/rpictogrify_spec.rb
|
113
|
+
- spec/spec_helper.rb
|