dhtml 0.1.3 → 0.1.4

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: 0d19e6ad8effeadc4ba60d79a1df5cc0a66ca25e7c8f75f513e73faf439abccf
4
- data.tar.gz: 42e1449cda9a9874bd36bb0b261537c4f147b2af56b0e26aba742b231297332f
3
+ metadata.gz: 9fe9a81232d087f78f919f95b27cdffc5ccefd5a4134dad6ed21cce7e3856265
4
+ data.tar.gz: 4db4671909efeb3a9a149b56f8d8cc72c606fc2babc81a3ace13df126a1a7a29
5
5
  SHA512:
6
- metadata.gz: f26aaa41af798393b2865477d742bf59c9723dc3714d43e1f2e7c463c8465801c7947c1cc33b45671e05ef68f63bff1f7db5e684cbd50720d6df3f9cf18c286a
7
- data.tar.gz: 07c3a590c080c087a543628db94fe171e16f7746f7863110c82b7a9a6aa18a55378d39abb95b64abd96b47251b94e25d3e0f3b4831d2f652431e8637b09d2152
6
+ metadata.gz: 9a8daa8a23422a54a929ba5350a60795cd8b9b863fc59f71de0e9a57d4f2b299725d632b07d3c8f4d3bd9c1cefa50a6cde73a1a414bad7bf21cc5de7ee050755
7
+ data.tar.gz: 9943ffda42a1c42f04ee12338fd26fcb9e5725757292646107241457033810cef7383d2336fffff44dc7edbdfeb2fe7c3782b5c8f55f5e72312cd5663bc05914
data/CHANGELOG.md CHANGED
@@ -5,21 +5,20 @@ The format is based on [Keep a Changelog], and this project adheres to [Semantic
5
5
 
6
6
  ## [Unreleased]
7
7
 
8
- ## [0.1.3] - 2021-05-10
9
- ### Fixed
10
- - The gemspec no longer uses absolute paths for the sources.
11
-
12
- ## [0.1.2] - 2021-05-10
8
+ ## [0.1.4] - 2021-05-11
13
9
  ### Added
14
- - `reset` method so the document can be generated more than once.
10
+ - `pretty_html` method that formats the document in a way presentable to a human.
15
11
 
16
- ## [0.1.0] - 2021-05-10
17
- - Initial release
12
+ ### Fixed
13
+ - `write_html_tag` and `write_html_element` return the number of bytes written.
18
14
 
15
+ ## [0.1.3] - 2021-05-10
16
+ - Initial release
17
+ - Versions prior to this were yanked. The gems were packaged with absolute paths by mistake.
19
18
 
20
- [Unreleased]: https://github.com/hi5dev/dhtml/compare/v0.1.2...HEAD
21
- [0.1.2]: https://github.com/hi5dev/dhtml/compare/v0.1.2..v0.1.0
22
- [0.1.0]: https://github.com/hi5dev/dhtml/releases/tag/v0.1.0
19
+ [Unreleased]: https://github.com/hi5dev/dhtml/compare/v0.1.4...HEAD
20
+ [0.1.4]: https://github.com/hi5dev/dhtml/compare/v0.1.3..v0.1.4
21
+ [0.1.3]: https://github.com/hi5dev/dhtml/releases/tag/v0.1.3
23
22
 
24
23
  [Keep a Changelog]: https://keepachangelog.com/en/1.0.0/
25
24
  [Semantic Versioning]: https://semver.org/spec/v2.0.0.html
data/Gemfile CHANGED
File without changes
data/Gemfile.lock CHANGED
File without changes
data/LICENSE.txt CHANGED
File without changes
data/README.md CHANGED
File without changes
data/dhtml.gemspec CHANGED
File without changes
data/lib/dhtml.rb CHANGED
File without changes
@@ -97,6 +97,18 @@ module DHTML
97
97
 
98
98
  alias_method :h, :html_escape
99
99
 
100
+ # Reads and formats the document in a way presentable to a human.
101
+ #
102
+ # @note Not available to Opal.
103
+ # @param [String] indent string.
104
+ # @return [String]
105
+ # @since 0.1.4
106
+ def pretty_html(indent: ' ' * 2)
107
+ require 'cgi' unless defined?(CGI)
108
+
109
+ CGI.pretty(read_html, indent)
110
+ end if RUBY_ENGINE != 'opal'
111
+
100
112
  # Reads the entire HTML document.
101
113
  #
102
114
  # @return [String]
@@ -121,10 +133,14 @@ module DHTML
121
133
  # @return [Integer] Number of bytes written to the stream.
122
134
  # @since 0.1.0
123
135
  def write_html_element(tag, attributes = {})
136
+ length = document.length
137
+
124
138
  document << '<'
125
139
  document << tag
126
140
  document << " #{html_attributes(attributes)}" unless attributes.empty?
127
141
  document << '>'
142
+
143
+ document.length - length
128
144
  end
129
145
 
130
146
  # Write a tag to the HTML document.
@@ -142,6 +158,9 @@ module DHTML
142
158
  tag = tag.to_s
143
159
  tag = tag[1..-1] if tag[0] == '_'
144
160
 
161
+ # Used to calculate the number of bytes written for the return value.
162
+ length = document.length
163
+
145
164
  # Opening tag with its HTML attributes - e.g. <div id="main">
146
165
  write_html_element(tag, attributes)
147
166
 
@@ -153,6 +172,9 @@ module DHTML
153
172
 
154
173
  # Close the tag when necessary.
155
174
  document.write("</#{tag}>") if content.is_a?(String) || block_given? || !void?(tag.to_sym)
175
+
176
+ # Total number of bytes written by this method.
177
+ document.length - length
156
178
  end
157
179
  end
158
180
  end
data/lib/dhtml/opal.rb CHANGED
File without changes
data/lib/dhtml/version.rb CHANGED
@@ -5,5 +5,5 @@ module DHTML
5
5
  #
6
6
  # @see https://semver.org/spec/v2.0.0.html
7
7
  # @type [String]
8
- VERSION = '0.1.3'
8
+ VERSION = '0.1.4'
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dhtml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Travis Haynes