svg_icon 0.1.0 → 0.2.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.
@@ -6,6 +6,7 @@ module SvgIcon
6
6
 
7
7
  attr_accessor :icon
8
8
  attr_accessor :default_class
9
+ attr_accessor :extra_icons_path
9
10
 
10
11
  def initialize
11
12
  @icon = DEFAULT_ICON
@@ -3,7 +3,7 @@ module SvgIcon
3
3
  def svg_icon(name, options = {})
4
4
  options = options.dup
5
5
 
6
- icons = SvgIcon.icons
6
+ icons = SvgIcon.icons_json
7
7
  height = icons["height"] || 24
8
8
  width = icons["width"] || 24
9
9
 
@@ -18,7 +18,7 @@ module SvgIcon
18
18
  path = icons["icons"][name]["body"]
19
19
  "<svg xmlns='http://www.w3.org/2000/svg' #{icon_html_attributes(options)}>#{path}</svg>".html_safe
20
20
  rescue
21
- "<svg xmlns='http://www.w3.org/2000/svg' #{icon_html_attributes(options)}><!-- SVG icon file not found: '#{name}' --></svg></svg>".html_safe
21
+ "<svg xmlns='http://www.w3.org/2000/svg' #{icon_html_attributes(options)}><!-- SVG icon file not found: '#{name}' --></svg>".html_safe
22
22
  end
23
23
  end
24
24
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SvgIcon
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
data/lib/svg_icon.rb CHANGED
@@ -10,11 +10,45 @@ module SvgIcon
10
10
  class Error < StandardError; end
11
11
 
12
12
  extend self
13
+
14
+ def extra_file_data
15
+ extra_data_path = SvgIcon.configuration.extra_icons_path
16
+ return nil if extra_data_path.nil?
17
+ @extra_file_data ||= File.read(extra_data_path)
18
+ end
19
+
20
+ def extra_icons
21
+ return {} if extra_file_data.nil?
22
+ @extra_icons ||= MultiJson.load(extra_file_data)
23
+ end
24
+
25
+ # def file_data
26
+ # icons_data_path = SvgIcon.configuration.icons_data_path
27
+
28
+ # icons_path = if icons_data_path.present?
29
+ # File.join(icons_data_path)
30
+ # else
31
+ # File.join(__dir__, "data/#{SvgIcon.configuration.icon}.json")
32
+ # end
33
+ # @file_data ||= File.read(icons_path)
34
+ # end
35
+
13
36
  def file_data
14
- @file_data ||= File.read(File.join(__dir__, "data/#{SvgIcon.configuration.icon}.json"))
37
+ icons_path = File.join(__dir__, "data/#{SvgIcon.configuration.icon}.json")
38
+ @file_data ||= File.read(icons_path)
15
39
  end
16
40
 
17
41
  def icons
18
- @icons ||= MultiJson.load(file_data).freeze
42
+ @icons ||= MultiJson.load(file_data)
43
+ end
44
+
45
+ def icons_json
46
+ @icons_json ||= if extra_icons
47
+ puts "icons_json"
48
+ icons["icons"] = icons["icons"].merge(extra_icons)
49
+ icons
50
+ else
51
+ icons
52
+ end
19
53
  end
20
54
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: svg_icon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - doabit
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-03-30 00:00:00.000000000 Z
11
+ date: 2022-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json
@@ -40,6 +40,7 @@ files:
40
40
  - bin/setup
41
41
  - lib/data/bi.json
42
42
  - lib/data/bx.json
43
+ - lib/data/heroicons.json
43
44
  - lib/svg_icon.rb
44
45
  - lib/svg_icon/configuration.rb
45
46
  - lib/svg_icon/helper.rb