bridgetown-svg-inliner 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b634ed7e6fba114daf71e6f95a1211bdf4aea1cfef818062406f3369bea4408b
4
+ data.tar.gz: a30862bb9778ccc547dd591e6a7070b252bc3372376b32fc8561dc26ed2a3108
5
+ SHA512:
6
+ metadata.gz: 9bce347b447759deff51941c8e57db560c49d0cf438751a73b240f1edab6771dae6cc9e26e0cc5c1c9408aee023608c7620e301918fcab62984c8ae07b95ee71
7
+ data.tar.gz: 5f0ec950b228af41d318cfdfaa94f68afee4ade6f38bcd23c51ec8ff75edc619dc30f84d1040d0332bd438f59082212db0255af8c50cb37ca19f3dd83f7d8e3e
data/.gitignore ADDED
@@ -0,0 +1,40 @@
1
+ /vendor
2
+ /.bundle/
3
+ /.yardoc
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
11
+ *.bundle
12
+ *.so
13
+ *.o
14
+ *.a
15
+ mkmf.log
16
+ *.gem
17
+ Gemfile.lock
18
+ .bundle
19
+ .ruby-version
20
+
21
+ # Node
22
+ node_modules
23
+ .npm
24
+ .node_repl_history
25
+
26
+ # Yarn
27
+ yarn-error.log
28
+ yarn-debug.log*
29
+ .pnp/
30
+ .pnp.js
31
+
32
+ # Yarn Integrity file
33
+ .yarn-integrity
34
+
35
+ test/dest
36
+ .bridgetown-metadata
37
+ .bridgetown-cache
38
+ .bridgetown-webpack
39
+
40
+ .DS_Store
data/.rubocop.yml ADDED
@@ -0,0 +1,31 @@
1
+ require: rubocop-bridgetown
2
+
3
+ inherit_gem:
4
+ rubocop-bridgetown: .rubocop.yml
5
+
6
+ AllCops:
7
+ TargetRubyVersion: 2.6
8
+ Include:
9
+ - lib/**/*.rb
10
+ - test/**/*.rb
11
+
12
+ Exclude:
13
+ - .gitignore
14
+ - .rubocop.yml
15
+
16
+ - Gemfile.lock
17
+ - CHANGELOG.md
18
+ - LICENSE.md
19
+ - README.md
20
+
21
+ - script/**/*
22
+ - vendor/**/*
23
+
24
+ Style/MultilineIfModifier:
25
+ Enabled: false
26
+
27
+ Style/RescueStandardError:
28
+ Enabled: false
29
+
30
+ Lint/AmbiguousBlockAssociation:
31
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # main
2
+
3
+ # 1.0.0 / 17-06-2021
4
+
5
+ The initial release
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+ gemspec
5
+
6
+ gem "bridgetown", ENV["BRIDGETOWN_VERSION"] if ENV["BRIDGETOWN_VERSION"]
7
+
8
+ group :test do
9
+ gem "minitest"
10
+ gem "minitest-reporters"
11
+ gem "shoulda"
12
+ end
data/LICENSE.md ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021-present Ayush Newatia
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,77 @@
1
+ # Bridgetown SVG Inliner
2
+
3
+ A Bridgetown plugin that provides a liquid tag and ERB helper to inline SVG files within the HTML markup.
4
+
5
+ ## Installation
6
+
7
+ Run this command to add this plugin to your site's Gemfile:
8
+
9
+ ```shell
10
+ $ bundle add "bridgetown-svg-inliner" -g bridgetown_plugins
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ This plugin provides an `svg` tag in Liquid and an `svg` helper in ERB or other Tilt based templating langugages.
16
+
17
+ ```liquid
18
+ <!-- Liquid -->
19
+ {% svg "/assets/icons/thumbs-up.svg" %}
20
+ ```
21
+
22
+ ```erb
23
+ <!-- ERB -->
24
+ <%= svg "/assets/icons/thumbs-up.svg" %>
25
+ ```
26
+
27
+ ### Attributes
28
+
29
+ You can pass in attributes that you'd like to include on the `svg` tag in the HTML output.
30
+
31
+ ```liquid
32
+ <!-- Liquid -->
33
+ {% svg "/assets/icons/thumbs-up.svg", class: "icon" %}
34
+ ```
35
+
36
+ ```erb
37
+ <!-- ERB -->
38
+ <%= svg "/assets/icons/thumbs-up.svg", class: "icon" %>
39
+ ```
40
+
41
+ ```html
42
+ <!-- Output -->
43
+ <svg class="icon">
44
+ ...
45
+ </svg>
46
+ ```
47
+
48
+ ### Liquid variables
49
+
50
+ You can use Liquid variables by enclosing them in double braces (`{{ }}`)
51
+
52
+ ```liquid
53
+ <!-- Liquid -->
54
+ {% assign svg_file = "thumbs-up" %}
55
+ {% assign svg_class_list = "icon icon--small" %}
56
+ {% svg "/assets/icons/{{ svg_file }}.svg", class: "{{ svg_class_list }}" %}
57
+ ```
58
+
59
+ ## Testing
60
+
61
+ * Run `bundle exec rake test` to run the test suite
62
+ * Or run `script/cibuild` to validate with Rubocop and Minitest together.
63
+
64
+ ## Contributing
65
+
66
+ 1. Fork it (https://github.com/ayushn21/bridgetown-svg-inliner/fork)
67
+ 2. Clone the fork using `git clone` to your local development machine.
68
+ 3. Create your feature branch (`git checkout -b my-new-feature`)
69
+ 4. Commit your changes (`git commit -am 'Add some feature'`)
70
+ 5. Push to the branch (`git push origin my-new-feature`)
71
+ 6. Create a new Pull Request
72
+
73
+ ## License
74
+
75
+ Bridgetown SVG Inliner is released under the [MIT License](https://opensource.org/licenses/MIT).
76
+
77
+ Copyright © 2021 [Ayush Newatia](https://twitter.com/ayushn21)
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/test_*.rb"]
8
+ t.warning = false
9
+ end
10
+
11
+ task :default => :test
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/bridgetown-svg-inliner/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "bridgetown-svg-inliner"
7
+ spec.version = BridgetownSvgInliner::VERSION
8
+ spec.author = "Ayush Newatia"
9
+ spec.email = "ayush@hey.com"
10
+ spec.summary = "Liquid and ERB helper for Bridgetown to inline SVG files within HTML"
11
+ spec.homepage = "https://github.com/ayushn21/bridgetown-svg-inliner"
12
+ spec.license = "MIT"
13
+
14
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r!^(test|script)/!) }
15
+ spec.test_files = spec.files.grep(%r!^test/!)
16
+ spec.require_paths = ["lib"]
17
+ spec.metadata = {}
18
+
19
+ spec.required_ruby_version = ">= 2.6.0"
20
+
21
+ spec.add_dependency "bridgetown", ">= 0.20", "< 2.0"
22
+ spec.add_dependency "nokogiri"
23
+
24
+ spec.add_development_dependency "bundler"
25
+ spec.add_development_dependency "rake", "~> 12.0"
26
+ spec.add_development_dependency "rubocop-bridgetown", "~> 0.2"
27
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bridgetown"
4
+ require "nokogiri"
5
+ require "bridgetown-svg-inliner/builder"
6
+
7
+ module BridgetownSvgInliner
8
+ autoload :LiquidAttributes, "bridgetown-svg-inliner/liquid_attributes"
9
+ end
10
+
11
+ BridgetownSvgInliner::Builder.register
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BridgetownSvgInliner
4
+ class Builder < Bridgetown::Builder
5
+ def build
6
+ liquid_tag "svg" do |attributes, tag|
7
+ attributes = Liquid::Template.parse(attributes).render(tag.context)
8
+ attributes = LiquidAttributes.new(attributes)
9
+
10
+ render attributes.path, attributes.args
11
+ end
12
+
13
+ helper "svg" do |path, **attributes|
14
+ render path, attributes
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ def render(path, html_attributes)
21
+ file = File.read(site.in_source_dir(path))
22
+ xml = Nokogiri::XML(file)
23
+ html_attributes&.each { |key, value| xml.root.set_attribute(key, value) }
24
+ xml.root.to_xml.html_safe
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BridgetownSvgInliner
4
+ class LiquidAttributes
5
+ attr_reader :path, :args
6
+
7
+ def initialize(attributes)
8
+ path, args = attributes.split(",", 2)
9
+
10
+ @path = unescape_string(path)
11
+ @args = args.scan(Liquid::TagAttributes).map do |arg|
12
+ [arg[0], unescape_string(arg[1])]
13
+ end.to_h if args.present?
14
+ end
15
+
16
+ private
17
+
18
+ def unescape_string(string)
19
+ string.undump
20
+ rescue
21
+ string
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BridgetownSvgInliner
4
+ VERSION = "1.0.0"
5
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bridgetown-svg-inliner
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Ayush Newatia
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-06-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bridgetown
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0.20'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '2.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '0.20'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '2.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: nokogiri
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rake
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '12.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '12.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rubocop-bridgetown
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '0.2'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '0.2'
89
+ description:
90
+ email: ayush@hey.com
91
+ executables: []
92
+ extensions: []
93
+ extra_rdoc_files: []
94
+ files:
95
+ - ".gitignore"
96
+ - ".rubocop.yml"
97
+ - CHANGELOG.md
98
+ - Gemfile
99
+ - LICENSE.md
100
+ - README.md
101
+ - Rakefile
102
+ - bridgetown-svg-inliner.gemspec
103
+ - lib/bridgetown-svg-inliner.rb
104
+ - lib/bridgetown-svg-inliner/builder.rb
105
+ - lib/bridgetown-svg-inliner/liquid_attributes.rb
106
+ - lib/bridgetown-svg-inliner/version.rb
107
+ homepage: https://github.com/ayushn21/bridgetown-svg-inliner
108
+ licenses:
109
+ - MIT
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: 2.6.0
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubygems_version: 3.1.4
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Liquid and ERB helper for Bridgetown to inline SVG files within HTML
130
+ test_files: []