custom_tag 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6a80dd1476c2c27655a8b83566e873e01f6b210b1572b2b72e323aa50efc68f2
4
- data.tar.gz: ed27c8f2294f0ce99e1bea9527eae578b43a505fd7566d3002b8ba3fce2cbff5
3
+ metadata.gz: 0dfccbf62198fd61a1e7ea003c67c1ceb3391581993e0c5005e205e1c5b2c165
4
+ data.tar.gz: 19606024d58651af802af5e588b34517c690c862cd394dba8046265a043b5e33
5
5
  SHA512:
6
- metadata.gz: 9d60a8b0e424a715b079df274982a35bf0db7adf6893cd86938455e90e815f53c6d3af2d5eac9065f9e7c727c4c2af67ed48060fa73e275385b5ed144fac1fba
7
- data.tar.gz: e14cb994cf2d986aef92b5b52824eafa195dfea5d966d43ed134a53c941a212a49e890c3ddec5501d297d323892fb538e30d0a6ed2855e257a27ce7d25476198
6
+ metadata.gz: 554eb2aaa0f13e077e0309a9268a7bf80165473a24c36a4784b9fbf6659644c11d7ea08ee2ec77215765c5766be66f069c5f644389029f01ce226ad6e784f44a
7
+ data.tar.gz: 33ef60f7c42ca57dec42022e2fda73d4e545574964a23ee86e70653dc307e378a00658f6b6b06a22fb041f3d729ff68c76cf7c735a2934fd05ee86efdbdc00a8
data/.rubocop.yml ADDED
@@ -0,0 +1,338 @@
1
+ require:
2
+ - rubocop-performance
3
+
4
+ AllCops:
5
+ SuggestExtensions: false
6
+ NewCops: enable
7
+ Exclude:
8
+ - 'db/**/*'
9
+ - 'config/**/*'
10
+ - 'script/**/*'
11
+ - 'node_modules/**/*'
12
+ - 'doc/**/*'
13
+ - 'bin/**/*'
14
+ - 'Gemfile'
15
+ - 'Rakefile'
16
+ - 'app/views/sitemap/index.xml.builder'
17
+ - 'Guardfile'
18
+ - 'spec/**/*.rb'
19
+ - vendor/bundle/**/*
20
+ Performance:
21
+ Exclude:
22
+ - 'spec/**/*'
23
+ Style/FormatStringToken:
24
+ EnforcedStyle: unannotated
25
+ Style/FetchEnvVar:
26
+ Enabled: false
27
+ Style/StringChars:
28
+ Enabled: false
29
+ Naming/BlockForwarding:
30
+ EnforcedStyle: explicit
31
+ Metrics/ClassLength:
32
+ Enabled: false
33
+ Naming/MethodParameterName:
34
+ Enabled: false
35
+ Lint/SuppressedException:
36
+ Enabled: false
37
+ Metrics/ParameterLists:
38
+ Enabled: false
39
+ Metrics/BlockNesting:
40
+ Enabled: false
41
+ Metrics/BlockLength:
42
+ Enabled: false
43
+ Metrics/ModuleLength:
44
+ Enabled: false
45
+ Metrics/CyclomaticComplexity:
46
+ Enabled: false
47
+ Metrics/PerceivedComplexity:
48
+ Enabled: false
49
+ Metrics/MethodLength:
50
+ Enabled: false
51
+ Layout/HashAlignment:
52
+ Enabled: false
53
+ Layout/ArgumentAlignment:
54
+ Enabled: false
55
+ Layout/LineLength:
56
+ Enabled: false
57
+ Layout/SpaceAroundMethodCallOperator:
58
+ Enabled: true
59
+ Lint/RaiseException:
60
+ Enabled: true
61
+ Lint/StructNewOverride:
62
+ Enabled: true
63
+ Style/ExponentialNotation:
64
+ Enabled: true
65
+ Style/HashEachMethods:
66
+ Enabled: true
67
+ Style/Documentation:
68
+ Enabled: false
69
+ Bundler/OrderedGems:
70
+ Enabled: false
71
+ Style/FrozenStringLiteralComment:
72
+ Enabled: false
73
+ Style/TrailingCommaInHashLiteral:
74
+ Enabled: false
75
+ Layout/SpaceBeforeSemicolon:
76
+ Enabled: false
77
+ Style/ClassAndModuleChildren:
78
+ Enabled: false
79
+ Metrics/AbcSize:
80
+ Enabled: false
81
+ Lint/RescueException:
82
+ Enabled: false
83
+ Layout/MultilineMethodCallIndentation:
84
+ Enabled: false
85
+
86
+ # Prefer &&/|| over and/or.
87
+ Style/AndOr:
88
+ Enabled: true
89
+
90
+ Style/FormatString:
91
+ EnforcedStyle: percent
92
+
93
+ # Align `when` with `case`.
94
+ Layout/CaseIndentation:
95
+ Enabled: false
96
+
97
+ Layout/ClosingHeredocIndentation:
98
+ Enabled: true
99
+
100
+ # Align comments with method definitions.
101
+ Layout/CommentIndentation:
102
+ Enabled: true
103
+
104
+ Layout/ElseAlignment:
105
+ Enabled: true
106
+
107
+ Style/RedundantRegexpEscape:
108
+ Enabled: false
109
+
110
+ Style/RaiseArgs:
111
+ EnforcedStyle: compact
112
+
113
+ # Align `end` with the matching keyword or starting expression except for
114
+ # assignments, where it should be aligned with the LHS.
115
+ Layout/EndAlignment:
116
+ Enabled: true
117
+ EnforcedStyleAlignWith: variable
118
+ AutoCorrect: true
119
+
120
+ Layout/EmptyLineAfterMagicComment:
121
+ Enabled: true
122
+
123
+ Layout/EmptyLinesAroundAccessModifier:
124
+ Enabled: false
125
+
126
+ Layout/EmptyLinesAroundBlockBody:
127
+ Enabled: true
128
+
129
+ # In a regular class definition, no empty lines around the body.
130
+ Layout/EmptyLinesAroundClassBody:
131
+ Enabled: true
132
+
133
+ # In a regular method definition, no empty lines around the body.
134
+ Layout/EmptyLinesAroundMethodBody:
135
+ Enabled: true
136
+
137
+ # In a regular module definition, no empty lines around the body.
138
+ Layout/EmptyLinesAroundModuleBody:
139
+ Enabled: true
140
+
141
+ # Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }.
142
+ Style/HashSyntax:
143
+ Enabled: true
144
+ EnforcedShorthandSyntax: never
145
+
146
+ Layout/FirstArgumentIndentation:
147
+ Enabled: true
148
+
149
+ Style/RescueModifier:
150
+ Enabled: false
151
+
152
+ # Method definitions after `private` or `protected` isolated calls need one
153
+ # extra level of indentation.
154
+ Layout/IndentationConsistency:
155
+ Enabled: false
156
+
157
+ # Two spaces, no tabs (for indentation).
158
+ Layout/IndentationWidth:
159
+ Enabled: true
160
+
161
+ Layout/LeadingCommentSpace:
162
+ Enabled: true
163
+
164
+ Layout/SpaceAfterColon:
165
+ Enabled: true
166
+
167
+ Layout/SpaceAfterComma:
168
+ Enabled: true
169
+
170
+ Layout/SpaceAfterSemicolon:
171
+ Enabled: true
172
+
173
+ Layout/SpaceAroundEqualsInParameterDefault:
174
+ Enabled: true
175
+
176
+ Layout/SpaceAroundKeyword:
177
+ Enabled: true
178
+
179
+ Layout/SpaceBeforeComma:
180
+ Enabled: true
181
+
182
+ Layout/SpaceBeforeComment:
183
+ Enabled: true
184
+
185
+ Layout/SpaceBeforeFirstArg:
186
+ Enabled: true
187
+
188
+ Style/DefWithParentheses:
189
+ Enabled: true
190
+
191
+ Style/MethodDefParentheses:
192
+ Enabled: true
193
+
194
+ Style/RedundantFreeze:
195
+ Enabled: true
196
+
197
+ # Use `foo {}` not `foo{}`.
198
+ Layout/SpaceBeforeBlockBraces:
199
+ Enabled: true
200
+
201
+ # Use `foo { bar }` not `foo {bar}`.
202
+ Layout/SpaceInsideBlockBraces:
203
+ Enabled: true
204
+ EnforcedStyleForEmptyBraces: space
205
+
206
+ # Use `{ a: 1 }` not `{a:1}`.
207
+ Layout/SpaceInsideHashLiteralBraces:
208
+ Enabled: true
209
+
210
+ Layout/SpaceInsideParens:
211
+ Enabled: true
212
+
213
+ # Check quotes usage according to lint rule below.
214
+ Style/StringLiterals:
215
+ Enabled: true
216
+ EnforcedStyle: double_quotes
217
+ SupportedStyles:
218
+ - single_quotes
219
+ - double_quotes
220
+
221
+ Style/StringLiteralsInInterpolation:
222
+ Enabled: false
223
+
224
+ Style/HashLikeCase:
225
+ Enabled: false
226
+
227
+ Style/IfUnlessModifier:
228
+ Enabled: false
229
+
230
+ # Detect hard tabs, no hard tabs.
231
+ Layout/IndentationStyle:
232
+ Enabled: true
233
+
234
+ # Empty lines should not have any spaces.
235
+ Layout/TrailingEmptyLines:
236
+ Enabled: true
237
+
238
+ # No trailing whitespace.
239
+ Layout/TrailingWhitespace:
240
+ Enabled: true
241
+
242
+ # Use quotes for string literals when they are enough.
243
+ Style/RedundantPercentQ:
244
+ Enabled: true
245
+
246
+ Lint/AmbiguousOperator:
247
+ Enabled: true
248
+
249
+ Lint/AmbiguousRegexpLiteral:
250
+ Enabled: true
251
+
252
+ Lint/ErbNewArguments:
253
+ Enabled: true
254
+
255
+ Lint/ParenthesesAsGroupedExpression:
256
+ Enabled: false
257
+
258
+ # Use my_method(my_arg) not my_method( my_arg ) or my_method my_arg.
259
+ Lint/RequireParentheses:
260
+ Enabled: true
261
+
262
+ Lint/ShadowingOuterLocalVariable:
263
+ Enabled: true
264
+
265
+ Lint/RedundantStringCoercion:
266
+ Enabled: true
267
+
268
+ Lint/UriEscapeUnescape:
269
+ Enabled: true
270
+
271
+ Lint/UselessAssignment:
272
+ Enabled: true
273
+
274
+ Lint/DeprecatedClassMethods:
275
+ Enabled: true
276
+
277
+ Style/GuardClause:
278
+ Enabled: false
279
+
280
+ Style/ParenthesesAroundCondition:
281
+ Enabled: true
282
+
283
+ Style/HashTransformKeys:
284
+ Enabled: true
285
+
286
+ Style/HashTransformValues:
287
+ Enabled: true
288
+
289
+ Style/RedundantBegin:
290
+ Enabled: true
291
+
292
+ Style/RedundantReturn:
293
+ Enabled: true
294
+ AllowMultipleReturnValues: true
295
+
296
+ Style/Semicolon:
297
+ Enabled: true
298
+ AllowAsExpressionSeparator: true
299
+
300
+ # Prefer Foo.method over Foo::method
301
+ Style/ColonMethodCall:
302
+ Enabled: true
303
+
304
+ Style/TrivialAccessors:
305
+ Enabled: true
306
+
307
+ Style/BarePercentLiterals:
308
+ Enabled: false
309
+
310
+ Performance/FlatMap:
311
+ Enabled: true
312
+
313
+ Performance/RedundantMerge:
314
+ Enabled: true
315
+
316
+ Performance/StartWith:
317
+ Enabled: true
318
+
319
+ Performance/EndWith:
320
+ Enabled: true
321
+
322
+ Performance/RegexpMatch:
323
+ Enabled: true
324
+
325
+ Performance/ReverseEach:
326
+ Enabled: true
327
+
328
+ Performance/UnfreezeString:
329
+ Enabled: true
330
+
331
+ Style/IfInsideElse:
332
+ Enabled: false
333
+
334
+ Style/RegexpLiteral:
335
+ Enabled: false
336
+
337
+ Style/ParallelAssignment:
338
+ Enabled: false
data/.standard.yml CHANGED
@@ -1,3 +1,7 @@
1
1
  # For available configuration options, see:
2
2
  # https://github.com/testdouble/standard
3
3
  ruby_version: 2.6
4
+ ignore:
5
+ - '**/*':
6
+ - Style/StringLiterals
7
+ - Metrics/AbcSize
data/CHANGELOG.md CHANGED
@@ -1 +1,9 @@
1
1
  # CHANGELOG for CustomTag
2
+
3
+ ## 0.2.0 - 9 July 2023
4
+
5
+ Rack middleware implemented and documentation written.
6
+
7
+ ## 0.1.0 - 3 July 2023
8
+
9
+ Basics of this gem working, need to implement the Rack middleware, but the core replacement code is working.
data/Gemfile CHANGED
@@ -9,4 +9,7 @@ gem "rake", "~> 13.0"
9
9
 
10
10
  gem "rspec", "~> 3.0"
11
11
 
12
- gem "standard", "~> 1.3"
12
+ gem "rubocop"
13
+ gem "rubocop-performance"
14
+
15
+ gem "rack"
data/Gemfile.lock ADDED
@@ -0,0 +1,70 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ custom_tag (0.2.0)
5
+ nokogiri
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.4.2)
11
+ diff-lcs (1.5.0)
12
+ json (2.6.3)
13
+ nokogiri (1.15.2-arm64-darwin)
14
+ racc (~> 1.4)
15
+ nokogiri (1.15.2-x86_64-linux)
16
+ racc (~> 1.4)
17
+ parallel (1.23.0)
18
+ parser (3.2.2.1)
19
+ ast (~> 2.4.1)
20
+ racc (1.6.2)
21
+ rack (3.0.8)
22
+ rainbow (3.1.1)
23
+ rake (13.0.6)
24
+ regexp_parser (2.8.0)
25
+ rexml (3.2.5)
26
+ rspec (3.12.0)
27
+ rspec-core (~> 3.12.0)
28
+ rspec-expectations (~> 3.12.0)
29
+ rspec-mocks (~> 3.12.0)
30
+ rspec-core (3.12.2)
31
+ rspec-support (~> 3.12.0)
32
+ rspec-expectations (3.12.3)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.12.0)
35
+ rspec-mocks (3.12.5)
36
+ diff-lcs (>= 1.2.0, < 2.0)
37
+ rspec-support (~> 3.12.0)
38
+ rspec-support (3.12.0)
39
+ rubocop (1.52.0)
40
+ json (~> 2.3)
41
+ parallel (~> 1.10)
42
+ parser (>= 3.2.0.0)
43
+ rainbow (>= 2.2.2, < 4.0)
44
+ regexp_parser (>= 1.8, < 3.0)
45
+ rexml (>= 3.2.5, < 4.0)
46
+ rubocop-ast (>= 1.28.0, < 2.0)
47
+ ruby-progressbar (~> 1.7)
48
+ unicode-display_width (>= 2.4.0, < 3.0)
49
+ rubocop-ast (1.29.0)
50
+ parser (>= 3.2.1.0)
51
+ rubocop-performance (1.18.0)
52
+ rubocop (>= 1.7.0, < 2.0)
53
+ rubocop-ast (>= 0.4.0)
54
+ ruby-progressbar (1.13.0)
55
+ unicode-display_width (2.4.2)
56
+
57
+ PLATFORMS
58
+ arm64-darwin-22
59
+ x86_64-linux
60
+
61
+ DEPENDENCIES
62
+ custom_tag!
63
+ rack
64
+ rake (~> 13.0)
65
+ rspec (~> 3.0)
66
+ rubocop
67
+ rubocop-performance
68
+
69
+ BUNDLED WITH
70
+ 2.4.6
data/README.md CHANGED
@@ -1,6 +1,83 @@
1
1
  # CustomTag
2
2
 
3
- > CustomTag allows you to use custom HTML tags in your Rails project and have them be replaced with standard HTML tags and attributes.
3
+ > CustomTag allows you to use custom HTML tags in your Rails project and have them be replaced with standard HTML tags and attributes. Brought on by jealousy of extracting TailwindCSS classes to simple components in frontend frameworks.
4
+
5
+ ## Usage
6
+
7
+ This gem allows you write custom HTML tags in your HTML output and have them replaced with other tags. For example you could do the following:
8
+
9
+ ```html
10
+ <my-card>
11
+ <h3>Your name here</h3>
12
+ <div>Job title</div>
13
+ </my-card>
14
+ ```
15
+
16
+ And it can be replaced with:
17
+
18
+ ```html
19
+ <div class="p-4 bg-white border border-gray-200 shadow-lg">
20
+ <h3>Your name here</h3>
21
+ <div>Job title</div>
22
+ </div>
23
+ ```
24
+
25
+ This keeps your TailwindCSS classes from being repeated all over your codebase, while not using `@apply` (<https://tailwindcss.com/docs/reusing-styles>). It's a middleground between full template systems like [Phlex](https://github.com/phlex-ruby/phlex) and [ViewComponent](https://viewcomponent.org) and just having lists of classes everywhere.
26
+
27
+ ### Defining your tags
28
+
29
+ To define your tags is nice and easy. Have one or more classes that are loaded early (maybe in `config/initializers` in Rails, or directly required if you're using Sinatra or some other lightweight framework) that define the tags you're creating, and how to replace the matching content with HTML. For example, to define a class that performs a single replacement, you could do:
30
+
31
+ ```ruby
32
+ class MyCard < CustomTag::Base
33
+ register :my_card, self
34
+
35
+ def self.build(_, attrs, content)
36
+ attrs["class"] = "p-4 bg-white border border-gray-200 shadow-lg #{attrs["class"]}".strip
37
+ super("div", attrs, content)
38
+ # The super will simply build an HTML tag from the details given
39
+ end
40
+ end
41
+ ```
42
+
43
+ You can call the `register` method with any of `under_scored`, `hyphen-ated` or `CamelCased` tags names and it will automatically convert between them to accept any one of them as the same thing.
44
+
45
+ If you wish you can have multiple tags defined in a single class and use the first parameters of `build` to distinguish between them:
46
+
47
+ ```ruby
48
+ class ApplicationCustomTags < CustomTag::Base
49
+ register :my_card, self
50
+
51
+ def self.build(tag_name, attrs, content)
52
+ case tag_name
53
+ when "my_card"
54
+ my_card(attrs, content)
55
+ when "..."
56
+ # ...
57
+ end
58
+ end
59
+
60
+ def self.my_card(attrs,content)
61
+ attrs["class"] = "p-4 bg-white border border-gray-200 shadow-lg #{attrs["class"]}".strip
62
+ "<div #{attrs.map { |k, v| "#{k}=\"#{v}\"" }.join(" ")}>#{content}</div>"
63
+ end
64
+ end
65
+ ```
66
+
67
+ ### Middleware
68
+
69
+ If you're using Rails, the CustomTag Middleware will be automatically registered for you as the last middleware to be called. If you want to use it yourself in a non-Rails app, you can use it like this:
70
+
71
+ ```ruby
72
+ require 'sinatra'
73
+ require 'custom_tag'
74
+
75
+ use CustomTag::Middleware
76
+
77
+ get '/hello' do
78
+ '<some HTML here... />'
79
+ end
80
+ ```
4
81
 
5
82
  ## Installation
6
83
 
@@ -8,19 +85,19 @@ Install the gem and add to the application's Gemfile by executing:
8
85
 
9
86
  bundle add custom_tag
10
87
 
88
+ Or adding `gem "custom_tag"` to your `Gemfile` and running `bundle install`.
89
+
11
90
  If bundler is not being used to manage dependencies, install the gem by executing:
12
91
 
13
92
  gem install custom_tag
14
93
 
15
- ## Usage
16
-
17
- TODO: Write usage instructions here
18
-
19
94
  ## Development
20
95
 
21
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
96
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
97
+
98
+ To install this gem onto your local machine, run `bundle exec rake install`.
22
99
 
23
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
100
+ To release a new version, update the version number in `version.rb`, edit the `CHANGELOG.md` file to explain the new release and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
24
101
 
25
102
  ## Contributing
26
103
 
data/Rakefile CHANGED
@@ -5,6 +5,4 @@ require "rspec/core/rake_task"
5
5
 
6
6
  RSpec::Core::RakeTask.new(:spec)
7
7
 
8
- require "standard/rake"
9
-
10
- task default: %i[spec standard]
8
+ task default: %i[spec rubocop]
data/custom_tag.gemspec CHANGED
@@ -30,9 +30,9 @@ Gem::Specification.new do |spec|
30
30
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
31
31
  spec.require_paths = ["lib"]
32
32
 
33
- # Uncomment to register a new dependency of your gem
34
- # spec.add_dependency "example-gem", "~> 1.0"
33
+ spec.add_dependency "nokogiri"
35
34
 
36
35
  # For more information and examples about making a new gem, check out our
37
36
  # guide at: https://bundler.io/guides/creating_gem.html
37
+ spec.metadata["rubygems_mfa_required"] = "true"
38
38
  end
@@ -0,0 +1,42 @@
1
+ module CustomTag
2
+ class Base
3
+ @@tags = {}
4
+
5
+ def self.register(tag_name, klass)
6
+ @@tags[tag_name.to_s] = klass
7
+ @@tags[tag_name.to_s.gsub(/([A-Z])/) { |m| "_#{m.downcase}" }] = klass
8
+ @@tags[tag_name.to_s.gsub(/([A-Z])/) { |m| "-#{m.downcase}" }] = klass
9
+ @@tags[tag_name.to_s.tr("_", "-").downcase] = klass
10
+ @@tags[tag_name.to_s.gsub(/_([a-z])/) { |m| m[1].upcase }] = klass
11
+ @@tags[tag_name.to_s.tr("-", "_").downcase] = klass
12
+ @@tags[tag_name.to_s.gsub(/-([a-z])/) { |m| m[1].upcase }] = klass
13
+ @@tags[tag_name.to_s.delete("-").downcase] = klass
14
+ @@tags[tag_name.to_s.delete("_").downcase] = klass
15
+ @@tags[tag_name.to_s.downcase] = klass
16
+ end
17
+
18
+ def self.tags
19
+ @@tags
20
+ end
21
+
22
+ def self.replace(tag_name, attrs, content)
23
+ ret = if @@tags[tag_name]
24
+ @@tags[tag_name].build(tag_name, attrs, content)
25
+ else
26
+ build(tag_name, attrs, content)
27
+ end
28
+
29
+ doc = Nokogiri::XML.fragment(ret)
30
+ doc.search("*").each do |element|
31
+ if CustomTag::Base.tags[element.name]
32
+ element.replace(CustomTag::Base.replace(element.name, element.attributes, element.content))
33
+ end
34
+ end
35
+ doc.to_html.strip
36
+ end
37
+
38
+ def self.build(tag_name, attrs, content)
39
+ "<#{tag_name} #{attrs.map { |k, v| "#{k}=\"#{v}\"" }.join(" ")}>#{content}</#{tag_name}>"
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,15 @@
1
+ module CustomTag
2
+ class Middleware
3
+ def initialize(app)
4
+ @app = app
5
+ end
6
+
7
+ def call(env)
8
+ code, headers, response = @app.call(env)
9
+
10
+ response[0] = CustomTag.parse_and_replace(response[0]) if headers["Content-Type"]&.include?("text/html")
11
+
12
+ [code, headers, response]
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,9 @@
1
+ if defined?(Rails::Railtie)
2
+ module CustomTag
3
+ class Railtie < Rails::Railtie
4
+ initializer do |app|
5
+ app.middleware.use Middleware
6
+ end
7
+ end
8
+ end
9
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CustomTag
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
data/lib/custom_tag.rb CHANGED
@@ -1,8 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "nokogiri"
3
4
  require_relative "custom_tag/version"
5
+ require_relative "custom_tag/base"
6
+ require_relative "custom_tag/middleware"
7
+ require_relative "custom_tag/railties"
4
8
 
5
9
  module CustomTag
6
10
  class Error < StandardError; end
7
- # Your code goes here...
11
+
12
+ def self.parse_and_replace(content)
13
+ doc = Nokogiri::HTML.parse(content)
14
+ doc.search("*").each do |element|
15
+ if CustomTag::Base.tags[element.name]
16
+ element.replace(CustomTag::Base.replace(element.name, element.attributes, element.children.to_html))
17
+ end
18
+ end
19
+ doc.to_html(save_with: 0)
20
+ end
8
21
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: custom_tag
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
  - Andy Jeffries
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-06-07 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2023-07-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
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'
13
27
  description: Jealous of custom <tags> in JS frameworks and want them in your Rails
14
28
  apps? CustomTag allows you to use custom HTML tags in your Rails project and have
15
29
  them be replaced with standard HTML tags and attributes.
@@ -20,13 +34,18 @@ extensions: []
20
34
  extra_rdoc_files: []
21
35
  files:
22
36
  - ".rspec"
37
+ - ".rubocop.yml"
23
38
  - ".standard.yml"
24
39
  - CHANGELOG.md
25
40
  - Gemfile
41
+ - Gemfile.lock
26
42
  - README.md
27
43
  - Rakefile
28
44
  - custom_tag.gemspec
29
45
  - lib/custom_tag.rb
46
+ - lib/custom_tag/base.rb
47
+ - lib/custom_tag/middleware.rb
48
+ - lib/custom_tag/railties.rb
30
49
  - lib/custom_tag/version.rb
31
50
  - sig/custom_tag.rbs
32
51
  homepage: https://github.com/andyjeffries/customtag
@@ -35,6 +54,7 @@ metadata:
35
54
  homepage_uri: https://github.com/andyjeffries/customtag
36
55
  source_code_uri: https://github.com/andyjeffries/customtag
37
56
  changelog_uri: https://github.com/andyjeffries/customtag/blob/master/CHANGELOG.md
57
+ rubygems_mfa_required: 'true'
38
58
  post_install_message:
39
59
  rdoc_options: []
40
60
  require_paths: