svg_icon 0.1.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.
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SvgIcon
4
+ class Configuration
5
+ DEFAULT_ICON = "bi"
6
+
7
+ attr_accessor :icon
8
+ attr_accessor :default_class
9
+
10
+ def initialize
11
+ @icon = DEFAULT_ICON
12
+ end
13
+ end
14
+
15
+ def self.configuration
16
+ @configuration ||= Configuration.new
17
+ end
18
+
19
+ def self.configuration=(config)
20
+ @configuration = config
21
+ end
22
+
23
+ def self.configure
24
+ yield configuration
25
+ end
26
+ end
@@ -0,0 +1,31 @@
1
+ module SvgIcon
2
+ module Helper
3
+ def svg_icon(name, options = {})
4
+ options = options.dup
5
+
6
+ icons = SvgIcon.icons
7
+ height = icons["height"] || 24
8
+ width = icons["width"] || 24
9
+
10
+ options[:viewBox] = "0 0 #{width} #{height}"
11
+ options[:version] = "1.1"
12
+
13
+ default_class = SvgIcon.configuration.default_class
14
+
15
+ options[:class] = "#{default_class} #{options[:class]}".strip if default_class.present?
16
+
17
+ begin
18
+ path = icons["icons"][name]["body"]
19
+ "<svg xmlns='http://www.w3.org/2000/svg' #{icon_html_attributes(options)}>#{path}</svg>".html_safe
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
22
+ end
23
+ end
24
+
25
+ def icon_html_attributes(options)
26
+ attrs = ""
27
+ options.each { |attr, value| attrs += "#{attr}=\"#{value}\" " }
28
+ attrs.strip
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SvgIcon
4
+ VERSION = "0.1.0"
5
+ end
data/lib/svg_icon.rb ADDED
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "svg_icon/configuration"
4
+ require_relative "svg_icon/helper"
5
+ require_relative "svg_icon/version"
6
+
7
+ require "multi_json"
8
+
9
+ module SvgIcon
10
+ class Error < StandardError; end
11
+
12
+ extend self
13
+ def file_data
14
+ @file_data ||= File.read(File.join(__dir__, "data/#{SvgIcon.configuration.icon}.json"))
15
+ end
16
+
17
+ def icons
18
+ @icons ||= MultiJson.load(file_data).freeze
19
+ end
20
+ end
data/svg_icon.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/svg_icon/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "svg_icon"
7
+ spec.version = SvgIcon::VERSION
8
+ spec.authors = ["doabit"]
9
+ spec.email = ["doinsist@gmail.com"]
10
+
11
+ spec.summary = "Svg icon render helper for rails"
12
+ spec.description = "Svg icon render helper for rails."
13
+ spec.homepage = "https://github.com/ruby-gems/svg_icon"
14
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = spec.homepage
18
+ spec.metadata["changelog_uri"] = spec.homepage
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
24
+ end
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ # Uncomment to register a new dependency of your gem
30
+ spec.add_dependency "multi_json"
31
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: svg_icon
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - doabit
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-03-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: multi_json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Svg icon render helper for rails.
28
+ email:
29
+ - doinsist@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - Gemfile
36
+ - Gemfile.lock
37
+ - README.md
38
+ - Rakefile
39
+ - bin/console
40
+ - bin/setup
41
+ - lib/data/bi.json
42
+ - lib/data/bx.json
43
+ - lib/svg_icon.rb
44
+ - lib/svg_icon/configuration.rb
45
+ - lib/svg_icon/helper.rb
46
+ - lib/svg_icon/version.rb
47
+ - svg_icon.gemspec
48
+ homepage: https://github.com/ruby-gems/svg_icon
49
+ licenses: []
50
+ metadata:
51
+ homepage_uri: https://github.com/ruby-gems/svg_icon
52
+ source_code_uri: https://github.com/ruby-gems/svg_icon
53
+ changelog_uri: https://github.com/ruby-gems/svg_icon
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 2.3.0
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubygems_version: 3.2.3
70
+ signing_key:
71
+ specification_version: 4
72
+ summary: Svg icon render helper for rails
73
+ test_files: []