hamlit 2.9.0 → 2.9.1

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
- SHA256:
3
- metadata.gz: 587d2b8d01739c5529f342f9f316b9d13dcec5c9ba4ca693072e83da857fdf20
4
- data.tar.gz: 91372701c50b63c2acbcc0f259987da4200a444c33371b1908670edc4c02493f
2
+ SHA1:
3
+ metadata.gz: bc45e545339c68fa4be81ef0dade7e48023f2529
4
+ data.tar.gz: c78dad0eb8daeceed3aaca230a3587dd39207a02
5
5
  SHA512:
6
- metadata.gz: 19f57ff4a0c28e5c6759c54120b37104ae3e4eff9e92cde062da1f195b8c39e3ef38a1f1eef4276fff22bd0961dd1cac126c3bdc38ca03137475ff5cc101fdb9
7
- data.tar.gz: 418735e4c178d9a7bf96d6bbc432a0f00da2fd4068df1bee01254a864f2675c9ebe05c5a391a78c9912095f17b666cb9e688b24e30f33b8390bb86741d9228b5
6
+ metadata.gz: 9f2ae53cc63fc0c3a081d776dc156b5e6fa0138d598b4981030ea98117ef14633bc2c04c5e1d94aca8a7f610ba59d8990a920c87a57c8c11ee5052ffc67a2300
7
+ data.tar.gz: 51ddf158f1e3fefa9d3e338ea4b72a65065d7c46b3be992685e605950ac1cfceef21f1487b4f87a55c9ed8f0e2affb37a80d5413ced67e8b61db827c8459b734
@@ -17,6 +17,8 @@ matrix:
17
17
  env: TASK=test
18
18
  - rvm: ruby-head
19
19
  env: TASK=test
20
+ - rvm: jruby-9.1.9.0
21
+ env: TASK=test
20
22
  - rvm: 2.4.0
21
23
  env: TASK=bench TEMPLATE=benchmark/boolean_attribute.haml,benchmark/class_attribute.haml,benchmark/id_attribute.haml,benchmark/data_attribute.haml,benchmark/common_attribute.haml
22
24
  - rvm: 2.4.0
@@ -4,11 +4,15 @@ All notable changes to this project will be documented in this file. This
4
4
  project adheres to [Semantic Versioning](http://semver.org/). This change log is based upon
5
5
  [keep-a-changelog](https://github.com/olivierlacan/keep-a-changelog).
6
6
 
7
+ ## [2.9.1](https://github.com/k0kubun/hamlit/compare/v2.9.0...v2.9.1) - 2018-11-01
8
+
9
+ - Start supporting JRuby [#100](https://github.com/k0kubun/hamlit/issues/100).
10
+
7
11
  ## [2.9.0](https://github.com/k0kubun/hamlit/compare/v2.8.10...v2.9.0) - 2018-10-16
8
12
 
9
13
  ### Added
10
14
 
11
- - Consider aria attribute as another attribute that supports hyphenation and boolean like data attribute.
15
+ - Consider aria attribute as another attribute that supports hyphenation and boolean like data attribute
12
16
  [#57](https://github.com/k0kubun/hamlit/pull/57). *Thanks to @francesco-loreti*
13
17
 
14
18
  ## [2.8.10](https://github.com/k0kubun/hamlit/compare/v2.8.9...v2.8.10) - 2018-09-05
data/Gemfile CHANGED
@@ -14,12 +14,15 @@ end
14
14
 
15
15
  gem 'benchmark-ips', '2.3.0'
16
16
  gem 'maxitest'
17
- gem 'pry-byebug'
18
17
 
19
- # To resolve circular require warning
20
- gem 'redcarpet', github: 'vmg/redcarpet'
18
+ if /java/ === RUBY_PLATFORM # JRuby
19
+ gem 'pandoc-ruby'
20
+ else
21
+ gem 'pry-byebug'
22
+ gem 'redcarpet', github: 'vmg/redcarpet' # To resolve circular require warning
21
23
 
22
- if RUBY_PLATFORM !~ /mswin|mingw|bccwin|wince/
23
- gem 'faml'
24
- gem 'stackprof'
24
+ if RUBY_PLATFORM !~ /mswin|mingw/
25
+ gem 'faml'
26
+ gem 'stackprof'
27
+ end
25
28
  end
data/Rakefile CHANGED
@@ -17,7 +17,22 @@ if Gem.win_platform?
17
17
  end
18
18
 
19
19
  require 'rake/testtask'
20
- require 'rake/extensiontask'
20
+ if /java/ === RUBY_PLATFORM
21
+ # require 'rake/javaextensiontask'
22
+ # Rake::JavaExtensionTask.new(:hamlit) do |ext|
23
+ # ext.ext_dir = 'ext/java'
24
+ # ext.lib_dir = 'lib/hamlit'
25
+ # end
26
+
27
+ task :compile do
28
+ # dummy for now
29
+ end
30
+ else
31
+ require 'rake/extensiontask'
32
+ Rake::ExtensionTask.new(:hamlit) do |ext|
33
+ ext.lib_dir = 'lib/hamlit'
34
+ end
35
+ end
21
36
 
22
37
  Dir['benchmark/*.rake'].each { |b| import(b) }
23
38
 
@@ -88,10 +103,6 @@ namespace :test do
88
103
  end
89
104
  end
90
105
 
91
- Rake::ExtensionTask.new(:hamlit) do |ext|
92
- ext.lib_dir = 'lib/hamlit'
93
- end
94
-
95
106
  desc 'bench task for CI'
96
107
  task bench: :compile do
97
108
  if ENV['SLIM_BENCH'] == '1'
@@ -17,9 +17,14 @@ Gem::Specification.new do |spec|
17
17
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|sample)/}) }
18
18
  spec.bindir = 'exe'
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
- spec.extensions = ['ext/hamlit/extconf.rb']
21
20
  spec.require_paths = ['lib']
22
- spec.required_ruby_version = '>= 2.1.0'
21
+
22
+ if /java/ === RUBY_PLATFORM
23
+ # spec.platform = 'java'
24
+ else
25
+ spec.extensions = ['ext/hamlit/extconf.rb']
26
+ spec.required_ruby_version = '>= 2.1.0'
27
+ end
23
28
 
24
29
  spec.add_dependency 'temple', '>= 0.8.0'
25
30
  spec.add_dependency 'thor'
@@ -34,7 +39,6 @@ Gem::Specification.new do |spec|
34
39
  spec.add_development_dependency 'rails', '>= 4.0.0'
35
40
  spec.add_development_dependency 'rake', '~> 10.0'
36
41
  spec.add_development_dependency 'rake-compiler'
37
- spec.add_development_dependency 'redcarpet'
38
42
  spec.add_development_dependency 'sass'
39
43
  spec.add_development_dependency 'slim'
40
44
  spec.add_development_dependency 'unindent'
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
- require 'hamlit/hamlit'
3
2
  require 'hamlit/object_ref'
4
- require 'hamlit/utils'
5
3
 
6
4
  module Hamlit::AttributeBuilder
7
5
  BOOLEAN_ATTRIBUTES = %w[disabled readonly multiple checked autobuffer
@@ -10,4 +8,166 @@ module Hamlit::AttributeBuilder
10
8
  autofocus novalidate formnovalidate open pubdate
11
9
  itemscope allowfullscreen default inert sortable
12
10
  truespeed typemustmatch download].freeze
11
+
12
+ if /java/ === RUBY_PLATFORM # JRuby
13
+ class << self
14
+ def build(escape_attrs, quote, format, object_ref, *hashes)
15
+ hashes << Hamlit::ObjectRef.parse(object_ref) if object_ref
16
+ buf = []
17
+ hash = merge_all_attrs(hashes)
18
+
19
+ keys = hash.keys.sort!
20
+ keys.each do |key|
21
+ case key
22
+ when 'id'.freeze
23
+ buf << " id=#{quote}#{build_id(escape_attrs, *hash[key])}#{quote}"
24
+ when 'class'.freeze
25
+ buf << " class=#{quote}#{build_class(escape_attrs, *hash[key])}#{quote}"
26
+ when 'data'.freeze
27
+ buf << build_data(escape_attrs, quote, *hash[key])
28
+ when *BOOLEAN_ATTRIBUTES, /\Adata-/
29
+ build_boolean!(escape_attrs, quote, format, buf, key, hash[key])
30
+ else
31
+ buf << " #{key}=#{quote}#{escape_html(escape_attrs, hash[key].to_s)}#{quote}"
32
+ end
33
+ end
34
+ buf.join
35
+ end
36
+
37
+ def build_id(escape_attrs, *values)
38
+ escape_html(escape_attrs, values.flatten.select { |v| v }.join('_'))
39
+ end
40
+
41
+ def build_class(escape_attrs, *values)
42
+ if values.size == 1
43
+ value = values.first
44
+ case
45
+ when value.is_a?(String)
46
+ # noop
47
+ when value.is_a?(Array)
48
+ value = value.flatten.select { |v| v }.map(&:to_s).sort.uniq.join(' ')
49
+ when value
50
+ value = value.to_s
51
+ else
52
+ return ''
53
+ end
54
+ return escape_html(escape_attrs, value)
55
+ end
56
+
57
+ classes = []
58
+ values.each do |value|
59
+ case
60
+ when value.is_a?(String)
61
+ classes += value.split(' ')
62
+ when value.is_a?(Array)
63
+ classes += value.select { |v| v }
64
+ when value
65
+ classes << value.to_s
66
+ end
67
+ end
68
+ escape_html(escape_attrs, classes.map(&:to_s).sort.uniq.join(' '))
69
+ end
70
+
71
+ def build_data(escape_attrs, quote, *hashes)
72
+ build_data_attribute(:data, escape_attrs, quote, *hashes)
73
+ end
74
+
75
+ def build_aria(escape_attrs, quote, *hashes)
76
+ build_data_attribute(:aria, escape_attrs, quote, *hashes)
77
+ end
78
+
79
+ private
80
+
81
+ def build_data_attribute(key, escape_attrs, quote, *hashes)
82
+ attrs = []
83
+ if hashes.size > 1 && hashes.all? { |h| h.is_a?(Hash) }
84
+ data_value = merge_all_attrs(hashes)
85
+ else
86
+ data_value = hashes.last
87
+ end
88
+ hash = flatten_attributes(key => data_value)
89
+
90
+ hash.sort_by(&:first).each do |key, value|
91
+ case value
92
+ when true
93
+ attrs << " #{key}"
94
+ when nil, false
95
+ # noop
96
+ else
97
+ attrs << " #{key}=#{quote}#{escape_html(escape_attrs, value.to_s)}#{quote}"
98
+ end
99
+ end
100
+ attrs.join
101
+ end
102
+
103
+ def flatten_attributes(attributes)
104
+ flattened = {}
105
+
106
+ attributes.each do |key, value|
107
+ case value
108
+ when attributes
109
+ when Hash
110
+ flatten_attributes(value).each do |k, v|
111
+ if k.nil?
112
+ flattened[key] = v
113
+ else
114
+ flattened["#{key}-#{k.to_s.gsub(/_/, '-')}"] = v
115
+ end
116
+ end
117
+ else
118
+ flattened[key] = value if value
119
+ end
120
+ end
121
+ flattened
122
+ end
123
+
124
+ def merge_all_attrs(hashes)
125
+ merged = {}
126
+ hashes.each do |hash|
127
+ hash.each do |key, value|
128
+ key = key.to_s
129
+ case key
130
+ when 'id'.freeze, 'class'.freeze, 'data'.freeze
131
+ merged[key] ||= []
132
+ merged[key] << value
133
+ else
134
+ merged[key] = value
135
+ end
136
+ end
137
+ end
138
+ merged
139
+ end
140
+
141
+ def build_boolean!(escape_attrs, quote, format, buf, key, value)
142
+ case value
143
+ when true
144
+ case format
145
+ when :xhtml
146
+ buf << " #{key}=#{quote}#{key}#{quote}"
147
+ else
148
+ buf << " #{key}"
149
+ end
150
+ when false, nil
151
+ # omitted
152
+ else
153
+ buf << " #{key}=#{quote}#{escape_html(escape_attrs, value)}#{quote}"
154
+ end
155
+ end
156
+
157
+ def escape_html(escape_attrs, str)
158
+ if escape_attrs
159
+ Hamlit::Utils.escape_html(str)
160
+ else
161
+ str
162
+ end
163
+ end
164
+ end
165
+ else
166
+ # Hamlit::AttributeBuilder.build
167
+ # Hamlit::AttributeBuilder.build_id
168
+ # Hamlit::AttributeBuilder.build_class
169
+ # Hamlit::AttributeBuilder.build_data
170
+ # Hamlit::AttributeBuilder.build_aria
171
+ require 'hamlit/hamlit'
172
+ end
13
173
  end
@@ -1,8 +1,16 @@
1
1
  # frozen_string_literal: true
2
- require 'hamlit/hamlit'
3
-
4
2
  module Hamlit
5
3
  module Utils
4
+ if /java/ === RUBY_PLATFORM # JRuby
5
+ require 'cgi/escape'
6
+
7
+ def self.escape_html(html)
8
+ CGI.escapeHTML(html.to_s)
9
+ end
10
+ else
11
+ require 'hamlit/hamlit' # Hamlit::Utils.escape_html
12
+ end
13
+
6
14
  def self.escape_html_safe(html)
7
15
  html.html_safe? ? html : escape_html(html)
8
16
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Hamlit
3
- VERSION = '2.9.0'
3
+ VERSION = '2.9.1'
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hamlit
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.9.0
4
+ version: 2.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takashi Kokubun
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-10-16 00:00:00.000000000 Z
11
+ date: 2018-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: temple
@@ -178,20 +178,6 @@ dependencies:
178
178
  - - ">="
179
179
  - !ruby/object:Gem::Version
180
180
  version: '0'
181
- - !ruby/object:Gem::Dependency
182
- name: redcarpet
183
- requirement: !ruby/object:Gem::Requirement
184
- requirements:
185
- - - ">="
186
- - !ruby/object:Gem::Version
187
- version: '0'
188
- type: :development
189
- prerelease: false
190
- version_requirements: !ruby/object:Gem::Requirement
191
- requirements:
192
- - - ">="
193
- - !ruby/object:Gem::Version
194
- version: '0'
195
181
  - !ruby/object:Gem::Dependency
196
182
  name: sass
197
183
  requirement: !ruby/object:Gem::Requirement
@@ -368,7 +354,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
368
354
  version: '0'
369
355
  requirements: []
370
356
  rubyforge_project:
371
- rubygems_version: 2.7.6
357
+ rubygems_version: 2.6.13
372
358
  signing_key:
373
359
  specification_version: 4
374
360
  summary: High Performance Haml Implementation