html_slice 0.2.4 → 0.2.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 47ec58956a24443617b6ec8ace88ef81b7bcbe835bef1708995b824f8080645c
4
- data.tar.gz: ee26639d56eb776d55ab9284833ff92fe681383c410a6e5f0c7d7c8cf8cc2af7
3
+ metadata.gz: cc11400cb9377b56446b53449e22298145f8ae75f1815236f273c5cd48790350
4
+ data.tar.gz: ea3bdc2af9e052d6310e146da37f2653cbdeb13aee3859acf24f2a32366f632e
5
5
  SHA512:
6
- metadata.gz: aa31246b60c626d96704dcc4bc358dafbeef40a9e68f6b59afad184bc7127f13be3e5f9dd17b0daa7b999d95147aa19a238e864ff710ebc7b5f14d686deb763a
7
- data.tar.gz: 653305df476ebde0cf5e370eb0fb43a8b4e8e329dcf1319a8271d7c1f4edc8fecb04630ee6b676851a5d113ed55ea774ba8fbddc75cb605f9582eb18ef34bb95
6
+ metadata.gz: cc47edc7352f2224d0aea43d271e5ef453eceb4b0d74039562a20ec75714c93c03f4b20f62e4f349526975665257753348520879699bb650d6b6bc6bf58855a2
7
+ data.tar.gz: dc524fdfbca74a3efb70af174bd4860c7f4ee5df377e680dfd3cdbe2467a932183e2ab5faafc9498b95f7b94e4597fd138b3ba098b62cba58ffe44b9da62503d
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module HtmlSlice
4
+ module Rails
5
+ def self.included(base)
6
+ base.class_eval do
7
+ include ActionView::RecordIdentifier
8
+ include ActionView::Helpers::FormHelper
9
+ include ActionView::Helpers::FormOptionsHelper
10
+ include ActionView::Helpers::TranslationHelper
11
+ include ActionView::Helpers::UrlHelper
12
+ include ::Rails.application.routes.url_helpers
13
+ include HtmlSlice
14
+
15
+ def controller
16
+ nil
17
+ end
18
+
19
+ def slice(slice_id = HtmlSlice::DEFAULT_SLICE, &block)
20
+ html_slice(slice_id, &block).html_safe
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HtmlSlice
4
- VERSION = "0.2.4"
4
+ VERSION = "0.2.6"
5
5
  end
data/lib/html_slice.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "html_slice/rails"
3
4
  require_relative "html_slice/version"
4
5
  require "cgi"
5
6
 
@@ -7,7 +8,7 @@ module HtmlSlice
7
8
  class Error < StandardError; end
8
9
 
9
10
  TAGS = %i[
10
- div title embed meta br a em b i ul ol li img table tbody thead tr th td
11
+ div title embed meta br a em b i ul ol li img table tbody thead tr th td strong
11
12
  form input button link h1 h2 h3 h4 h5 h6 hr span label iframe template main
12
13
  footer aside source section small nav area
13
14
  ].freeze
@@ -23,6 +24,16 @@ module HtmlSlice
23
24
  DEFAULT_SLICE = :default
24
25
  ATTRIBUTE_CACHE = {}
25
26
 
27
+ def self.slice(slice_id = DEFAULT_SLICE, wrap: ["", ""], &block)
28
+ @class ||= Class.new { include HtmlSlice }.new
29
+ @class.html_slice(slice_id, wrap: wrap, &block)
30
+ end
31
+
32
+ def self.layout(slice_id = DEFAULT_SLICE, &block)
33
+ @class ||= Class.new { include HtmlSlice }.new
34
+ @class.html_layout(slice_id, &block)
35
+ end
36
+
26
37
  def html_layout(slice_id = DEFAULT_SLICE, &block)
27
38
  html_slice(slice_id, wrap: ["<!DOCTYPE html><html>", "</html>"], &block)
28
39
  end
@@ -90,11 +101,10 @@ module HtmlSlice
90
101
 
91
102
  buffer << "<" << name_str
92
103
  unless attributes.empty?
93
- attributes_string = ATTRIBUTE_CACHE[attributes.dup] ||= begin
94
- attributes.map do |key, value|
95
- " #{key.to_s.tr('_', '-')}='#{value}'"
96
- end.join
97
- end
104
+ attributes_string = ATTRIBUTE_CACHE[attributes.dup] ||= attributes.map do |key, value|
105
+ " #{key.to_s.tr("_", "-")}='#{value}'"
106
+ end.join
107
+
98
108
  buffer << attributes_string
99
109
  end
100
110
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: html_slice
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - henrique-ft
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-12-21 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies: []
12
12
  description: Enable Ruby classes the ability to generate reusable pieces of html
13
13
  email:
@@ -17,6 +17,7 @@ extensions: []
17
17
  extra_rdoc_files: []
18
18
  files:
19
19
  - lib/html_slice.rb
20
+ - lib/html_slice/rails.rb
20
21
  - lib/html_slice/version.rb
21
22
  licenses: []
22
23
  metadata:
@@ -36,7 +37,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
36
37
  - !ruby/object:Gem::Version
37
38
  version: '0'
38
39
  requirements: []
39
- rubygems_version: 3.6.6
40
+ rubygems_version: 4.0.6
40
41
  specification_version: 4
41
42
  summary: Enable Ruby classes the ability to generate reusable pieces of html
42
43
  test_files: []