opal-haml 0.4.3 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/build.yml +29 -0
- data/CHANGELOG.md +30 -12
- data/Gemfile +26 -1
- data/README.md +4 -2
- data/Rakefile +4 -1
- data/config.ru +11 -2
- data/lib/opal/haml/builder.rb +1 -0
- data/lib/opal/haml/processor.rb +7 -18
- data/lib/opal/haml/version.rb +1 -1
- data/lib/opal/haml.rb +1 -1
- data/lib-opal/haml/attribute_builder.rb +184 -0
- data/{opal → lib-opal}/opal-haml.rb +4 -1
- data/opal-haml.gemspec +4 -3
- data/{spec → spec-opal/fixtures}/advanced.haml +0 -0
- data/spec-opal/fixtures/attributes_helper.haml +7 -0
- data/{spec → spec-opal/fixtures}/html_content.haml +0 -0
- data/{spec → spec-opal/fixtures}/simple.haml +0 -0
- data/spec-opal/haml_spec.rb +60 -0
- data/{spec → spec-opal}/output_buffer_spec.rb +0 -0
- data/spec-opal/spec_helper.rb +6 -0
- metadata +46 -31
- data/.travis.yml +0 -30
- data/spec/haml_spec.rb +0 -32
- data/spec/spec_helper.rb +0 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: caaa43696ff138938744b1bc2ebe269cee1db4eb9dfd786fa188434fa8a151e4
|
4
|
+
data.tar.gz: 12cea5167029244a89459504f4bc62f4ceb06ffce92d19d81a42d64b6ba0210c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 488af893b673e34f9cb9cb44e4f3764addc4f18607ee63fdab08a42ea2da59c6a9628a66601ac9f4d52283eaf987304be7b196850419cdc9c912f8fd34e196f7
|
7
|
+
data.tar.gz: 4bcc5f1cab067d59cc6c8757a4c1fe3d98e875f04b36fabb1a150c35aad087b6fe891a903b8d7c0685342fa3251e5a217d035bf59a66c0242f6ee8828e942607
|
@@ -0,0 +1,29 @@
|
|
1
|
+
name: Tests
|
2
|
+
on:
|
3
|
+
push:
|
4
|
+
branches:
|
5
|
+
- master
|
6
|
+
- "*-stable"
|
7
|
+
- "*/ci-check"
|
8
|
+
pull_request:
|
9
|
+
|
10
|
+
jobs:
|
11
|
+
tests:
|
12
|
+
name: Tests
|
13
|
+
strategy:
|
14
|
+
fail-fast: false
|
15
|
+
matrix:
|
16
|
+
ruby: [2.6, 2.7, 3.0]
|
17
|
+
runs-on: ubuntu-latest
|
18
|
+
steps:
|
19
|
+
- name: Checkout code
|
20
|
+
uses: actions/checkout@v2
|
21
|
+
|
22
|
+
- name: Setup Ruby
|
23
|
+
uses: ruby/setup-ruby@v1
|
24
|
+
with:
|
25
|
+
ruby-version: ${{ matrix.ruby }}
|
26
|
+
bundler-cache: true
|
27
|
+
|
28
|
+
- name: Run tests
|
29
|
+
run: bundle exec rake
|
data/CHANGELOG.md
CHANGED
@@ -1,37 +1,55 @@
|
|
1
|
+
## 0.5.0 2021-12-01
|
2
|
+
|
3
|
+
- Compatibility for Haml v5.2
|
4
|
+
|
5
|
+
- Support Sprockets 4.0
|
6
|
+
|
7
|
+
## 0.4.6 2019-07-13
|
8
|
+
|
9
|
+
- Add support for Opal v1.0
|
10
|
+
|
11
|
+
## 0.4.5 2018-03-19
|
12
|
+
|
13
|
+
- Avoid warning from Opal v0.11
|
14
|
+
|
15
|
+
## 0.4.4 2017-05-13
|
16
|
+
|
17
|
+
- Improve support for the attribute builder
|
18
|
+
|
1
19
|
## 0.4.3 2017-05-02
|
2
20
|
|
3
|
-
|
21
|
+
- Add support for Haml v5.0
|
4
22
|
|
5
23
|
## 0.4.2 2016-10-06
|
6
24
|
|
7
|
-
|
25
|
+
- Avoid Sprockets v3.7 deprecations
|
8
26
|
|
9
27
|
## 0.4.1 2015-11-02
|
10
28
|
|
11
|
-
|
29
|
+
- Add support for nested attribute hashes: `%div{ data: { foo: 123 } }` now becomes `<div data-foo="123"></div>`.
|
12
30
|
|
13
|
-
|
31
|
+
- Attribute values are now properly escaped.
|
14
32
|
|
15
33
|
## 0.4.0 2015-08-07
|
16
34
|
|
17
|
-
|
35
|
+
- Add support for Opal 0.8.
|
18
36
|
|
19
|
-
|
37
|
+
- Update the processor to reuse the good stuff from the Opal::Processor.
|
20
38
|
|
21
|
-
|
39
|
+
- Now each compiled template automatically requires `opal-haml` with the new module system.
|
22
40
|
|
23
41
|
## 0.3.0 2015-02-03
|
24
42
|
|
25
|
-
|
43
|
+
- Add support for new opal Builder processors.
|
26
44
|
|
27
|
-
|
45
|
+
- Implicitly require `opal-haml` when any haml template is required
|
28
46
|
|
29
|
-
|
47
|
+
- Cleanup generated code to be use Opal ERB runtime directly.
|
30
48
|
|
31
49
|
## 0.2.0 2013-12-17
|
32
50
|
|
33
|
-
|
51
|
+
- Remove opal-sprockets dependency
|
34
52
|
|
35
53
|
## 0.1.0 2013-12-17
|
36
54
|
|
37
|
-
|
55
|
+
- Initial release
|
data/Gemfile
CHANGED
@@ -1,3 +1,28 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
gemspec
|
3
|
-
|
3
|
+
|
4
|
+
github = -> repo { "https://github.com/#{repo}" }
|
5
|
+
version = -> rs { -> vs { Gem::Requirement.new(rs) === Gem::Version.new(vs) } }
|
6
|
+
haml_version = ENV['HAML_VERSION'] ? "~> #{ENV['HAML_VERSION']}" : ">= 0"
|
7
|
+
|
8
|
+
gem 'haml', haml_version
|
9
|
+
|
10
|
+
case ENV['OPAL_VERSION']
|
11
|
+
|
12
|
+
when 'local'
|
13
|
+
gem 'opal', path: '../opal'
|
14
|
+
gem 'opal-sprockets', path: '../opal-sprockets'
|
15
|
+
gem 'opal-rspec', path: '../opal-rspec'
|
16
|
+
|
17
|
+
when 'master'
|
18
|
+
gem 'opal', git: github['opal/opal'], branch: :master
|
19
|
+
gem 'opal-sprockets', git: github['opal/opal-sprockets']
|
20
|
+
gem 'opal-rspec', git: github['opal/opal-rspec'], branch: 'master', submodules: true
|
21
|
+
|
22
|
+
when version['~> 1.0.0']
|
23
|
+
gem 'opal-rspec', '~> 0.8.0.alpha1'
|
24
|
+
|
25
|
+
when version['~> 0.10.0']
|
26
|
+
gem 'opal', '~> 0.10.5'
|
27
|
+
|
28
|
+
end
|
data/README.md
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# Opal Haml
|
2
|
+
|
3
|
+
*Haml templates for Opal*
|
2
4
|
|
3
5
|
[![Build Status](https://travis-ci.org/opal/opal-haml.svg?branch=master)](https://travis-ci.org/opal/opal-haml)
|
4
6
|
|
@@ -79,7 +81,7 @@ $ bundle exec rackup
|
|
79
81
|
|
80
82
|
(The MIT License)
|
81
83
|
|
82
|
-
Copyright (C) 2013 by Adam Beynon
|
84
|
+
Copyright (C) 2013 by Adam Beynon, 2015 Elia Schito
|
83
85
|
|
84
86
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
85
87
|
of this software and associated documentation files (the "Software"), to deal
|
data/Rakefile
CHANGED
data/config.ru
CHANGED
@@ -1,10 +1,19 @@
|
|
1
1
|
require 'bundler'
|
2
2
|
Bundler.require
|
3
3
|
|
4
|
+
require 'opal-sprockets'
|
4
5
|
require 'opal-rspec'
|
5
6
|
|
6
|
-
|
7
|
+
OPAL_SPROCKETS_SERVER = defined?(Opal::Sprockets::Server) ? Opal::Sprockets::Server : Opal::Server
|
8
|
+
|
9
|
+
sprockets_env = Opal::RSpec::SprocketsEnvironment.new(
|
10
|
+
spec_pattern = 'spec-opal/**/*_spec.{rb,opal}',
|
11
|
+
spec_exclude_pattern = nil,
|
12
|
+
spec_files = nil,
|
13
|
+
default_path = 'spec-opal')
|
14
|
+
|
15
|
+
run OPAL_SPROCKETS_SERVER.new(sprockets: sprockets_env) { |s|
|
7
16
|
s.main = 'opal/rspec/sprockets_runner'
|
8
|
-
s.append_path 'spec'
|
17
|
+
s.append_path 'spec-opal'
|
9
18
|
s.debug = true
|
10
19
|
}
|
data/lib/opal/haml/builder.rb
CHANGED
data/lib/opal/haml/processor.rb
CHANGED
@@ -1,28 +1,17 @@
|
|
1
1
|
require 'haml'
|
2
|
-
require 'sprockets'
|
2
|
+
require 'opal-sprockets'
|
3
3
|
|
4
4
|
module Opal
|
5
5
|
module Haml
|
6
|
-
class Processor < ::Opal::Processor
|
7
|
-
|
8
|
-
|
9
|
-
def evaluate(context, locals, &block)
|
10
|
-
@data = Opal::Haml.compile_haml @data, context.logical_path.sub(/^templates\//, '')
|
6
|
+
class Processor < ::Opal::Sprockets::Processor
|
7
|
+
def call
|
8
|
+
@data = Opal::Haml.compile_haml @data, context.logical_path.sub(/#{Opal::REGEXP_START}templates\//, '')
|
11
9
|
super
|
12
10
|
end
|
13
|
-
|
14
|
-
def self.compiler_options
|
15
|
-
# otherwise would check current class `attr_accessor`s
|
16
|
-
::Opal::Processor.compiler_options
|
17
|
-
end
|
18
11
|
end
|
19
12
|
end
|
20
13
|
end
|
21
14
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
extra_args = []
|
26
|
-
end
|
27
|
-
|
28
|
-
Sprockets.register_engine '.haml', Opal::Haml::Processor, *extra_args
|
15
|
+
Sprockets.register_mime_type 'application/html+haml', extensions: ['.haml', '.html.haml']
|
16
|
+
Sprockets.register_transformer 'application/html+haml', 'application/javascript', Opal::Haml::Processor
|
17
|
+
Opal::Sprockets.register_mime_type 'application/html+haml'
|
data/lib/opal/haml/version.rb
CHANGED
data/lib/opal/haml.rb
CHANGED
@@ -0,0 +1,184 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (c) 2006-2009 Hampton Catlin and Natalie Weizenbaum
|
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.
|
23
|
+
module Haml
|
24
|
+
module AttributeBuilder
|
25
|
+
# https://html.spec.whatwg.org/multipage/syntax.html#attributes-2
|
26
|
+
INVALID_ATTRIBUTE_NAME_REGEX = /[ \0"'>\/=]/
|
27
|
+
|
28
|
+
class << self
|
29
|
+
def build_attributes(is_html, attr_wrapper, escape_attrs, hyphenate_data_attrs, attributes = {})
|
30
|
+
# @TODO this is an absolutely ridiculous amount of arguments. At least
|
31
|
+
# some of this needs to be moved into an instance method.
|
32
|
+
join_char = hyphenate_data_attrs ? '-' : '_'
|
33
|
+
|
34
|
+
attributes.each do |key, value|
|
35
|
+
if value.is_a?(Hash)
|
36
|
+
data_attributes = attributes.delete(key)
|
37
|
+
data_attributes = flatten_data_attributes(data_attributes, '', join_char)
|
38
|
+
data_attributes = build_data_keys(data_attributes, hyphenate_data_attrs, key)
|
39
|
+
verify_attribute_names!(data_attributes.keys)
|
40
|
+
attributes = data_attributes.merge(attributes)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
result = attributes.collect do |attr, value|
|
45
|
+
next if value.nil?
|
46
|
+
|
47
|
+
value = filter_and_join(value, ' ') if attr == 'class'
|
48
|
+
value = filter_and_join(value, '_') if attr == 'id'
|
49
|
+
|
50
|
+
if value == true
|
51
|
+
next " #{attr}" if is_html
|
52
|
+
next " #{attr}=#{attr_wrapper}#{attr}#{attr_wrapper}"
|
53
|
+
elsif value == false
|
54
|
+
next
|
55
|
+
end
|
56
|
+
|
57
|
+
value =
|
58
|
+
if escape_attrs == :once
|
59
|
+
Haml::Helpers.escape_once(value.to_s)
|
60
|
+
elsif escape_attrs
|
61
|
+
Haml::Helpers.html_escape(value.to_s)
|
62
|
+
else
|
63
|
+
value.to_s
|
64
|
+
end
|
65
|
+
" #{attr}=#{attr_wrapper}#{value}#{attr_wrapper}"
|
66
|
+
end
|
67
|
+
result.compact!
|
68
|
+
result.sort!
|
69
|
+
result.join
|
70
|
+
end
|
71
|
+
|
72
|
+
# @return [String, nil]
|
73
|
+
def filter_and_join(value, separator)
|
74
|
+
return '' if (value.respond_to?(:empty?) && value.empty?)
|
75
|
+
|
76
|
+
if value.is_a?(Array)
|
77
|
+
value = value.flatten
|
78
|
+
value.map! {|item| item ? item.to_s : nil}
|
79
|
+
value.compact!
|
80
|
+
value = value.join(separator)
|
81
|
+
else
|
82
|
+
value = value ? value.to_s : nil
|
83
|
+
end
|
84
|
+
!value.nil? && !value.empty? && value
|
85
|
+
end
|
86
|
+
|
87
|
+
# Merges two attribute hashes.
|
88
|
+
# This is the same as `to.merge!(from)`,
|
89
|
+
# except that it merges id, class, and data attributes.
|
90
|
+
#
|
91
|
+
# ids are concatenated with `"_"`,
|
92
|
+
# and classes are concatenated with `" "`.
|
93
|
+
# data hashes are simply merged.
|
94
|
+
#
|
95
|
+
# Destructively modifies `to`.
|
96
|
+
#
|
97
|
+
# @param to [{String => String,Hash}] The attribute hash to merge into
|
98
|
+
# @param from [{String => Object}] The attribute hash to merge from
|
99
|
+
# @return [{String => String,Hash}] `to`, after being merged
|
100
|
+
def merge_attributes!(to, from)
|
101
|
+
from.keys.each do |key|
|
102
|
+
to[key] = merge_value(key, to[key], from[key])
|
103
|
+
end
|
104
|
+
to
|
105
|
+
end
|
106
|
+
|
107
|
+
# Merge multiple values to one attribute value. No destructive operation.
|
108
|
+
#
|
109
|
+
# @param key [String]
|
110
|
+
# @param values [Array<Object>]
|
111
|
+
# @return [String,Hash]
|
112
|
+
def merge_values(key, *values)
|
113
|
+
values.inject(nil) do |to, from|
|
114
|
+
merge_value(key, to, from)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def verify_attribute_names!(attribute_names)
|
119
|
+
attribute_names.each do |attribute_name|
|
120
|
+
if attribute_name =~ INVALID_ATTRIBUTE_NAME_REGEX
|
121
|
+
raise InvalidAttributeNameError.new("Invalid attribute name '#{attribute_name}' was rendered")
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
private
|
127
|
+
|
128
|
+
# Merge a couple of values to one attribute value. No destructive operation.
|
129
|
+
#
|
130
|
+
# @param to [String,Hash,nil]
|
131
|
+
# @param from [Object]
|
132
|
+
# @return [String,Hash]
|
133
|
+
def merge_value(key, to, from)
|
134
|
+
if from.kind_of?(Hash) || to.kind_of?(Hash)
|
135
|
+
from = { nil => from } if !from.is_a?(Hash)
|
136
|
+
to = { nil => to } if !to.is_a?(Hash)
|
137
|
+
to.merge(from)
|
138
|
+
elsif key == 'id'
|
139
|
+
merged_id = filter_and_join(from, '_')
|
140
|
+
if to && merged_id
|
141
|
+
merged_id = "#{to}_#{merged_id}"
|
142
|
+
elsif to || merged_id
|
143
|
+
merged_id ||= to
|
144
|
+
end
|
145
|
+
merged_id
|
146
|
+
elsif key == 'class'
|
147
|
+
merged_class = filter_and_join(from, ' ')
|
148
|
+
if to && merged_class
|
149
|
+
merged_class = (merged_class.split(' ') | to.split(' ')).sort.join(' ')
|
150
|
+
elsif to || merged_class
|
151
|
+
merged_class ||= to
|
152
|
+
end
|
153
|
+
merged_class
|
154
|
+
else
|
155
|
+
from
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
def build_data_keys(data_hash, hyphenate, attr_name="data")
|
160
|
+
Hash[data_hash.map do |name, value|
|
161
|
+
if name == nil
|
162
|
+
[attr_name, value]
|
163
|
+
elsif hyphenate
|
164
|
+
["#{attr_name}-#{name.to_s.tr('_', '-')}", value]
|
165
|
+
else
|
166
|
+
["#{attr_name}-#{name}", value]
|
167
|
+
end
|
168
|
+
end]
|
169
|
+
end
|
170
|
+
|
171
|
+
def flatten_data_attributes(data, key, join_char, seen = [])
|
172
|
+
return {key => data} unless data.is_a?(Hash)
|
173
|
+
|
174
|
+
return {key => nil} if seen.include? data.object_id
|
175
|
+
seen << data.object_id
|
176
|
+
|
177
|
+
data.sort {|x, y| x[0].to_s <=> y[0].to_s}.inject({}) do |hash, (k, v)|
|
178
|
+
joined = key == '' ? k : [key, k].join(join_char)
|
179
|
+
hash.merge! flatten_data_attributes(v, joined, join_char, seen)
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'template'
|
2
|
+
require 'haml/attribute_builder'
|
2
3
|
|
3
4
|
module Haml
|
4
5
|
module Buffer
|
@@ -26,6 +27,8 @@ module Haml
|
|
26
27
|
.replace(/[\r\n]/g, ' ');
|
27
28
|
}
|
28
29
|
end
|
30
|
+
|
31
|
+
singleton_class.alias_method :html_escape_without_haml_xss, :html_escape
|
29
32
|
end
|
30
33
|
end
|
31
34
|
|
@@ -67,7 +70,7 @@ class Template
|
|
67
70
|
end
|
68
71
|
|
69
72
|
def _attribute_escape(value)
|
70
|
-
value.to_s.gsub
|
73
|
+
value.to_s.gsub(/['"&<>]/, '"' => '"', "'" => ''', '&' => '&', '<' => '<', '>' => '>')
|
71
74
|
end
|
72
75
|
end
|
73
76
|
end
|
data/opal-haml.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
|
|
7
7
|
s.version = Opal::Haml::VERSION
|
8
8
|
s.author = 'Adam Beynon'
|
9
9
|
s.email = 'adam@adambeynon.com'
|
10
|
-
s.homepage = '
|
10
|
+
s.homepage = 'https://github.com/opal/opal-haml#readme'
|
11
11
|
s.summary = 'Run Haml templates client-side with Opal'
|
12
12
|
s.description = 'Run Haml templates client-side with Opal.'
|
13
13
|
s.license = 'MIT'
|
@@ -17,9 +17,10 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
18
|
s.require_paths = ['lib']
|
19
19
|
|
20
|
-
s.add_dependency 'opal', '
|
20
|
+
s.add_dependency 'opal', ['>= 0.10', '< 2']
|
21
|
+
s.add_dependency 'opal-sprockets', '>= 0.5.0'
|
21
22
|
s.add_dependency 'haml'
|
22
23
|
|
23
|
-
s.add_development_dependency 'opal-rspec'
|
24
|
+
s.add_development_dependency 'opal-rspec'
|
24
25
|
s.add_development_dependency 'rake'
|
25
26
|
end
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'fixtures/simple'
|
3
|
+
require 'fixtures/advanced'
|
4
|
+
require 'fixtures/html_content'
|
5
|
+
require 'fixtures/attributes_helper'
|
6
|
+
|
7
|
+
describe "Haml files" do
|
8
|
+
let(:simple) { Template['fixtures/simple'] }
|
9
|
+
let(:advanced) { Template['fixtures/advanced'] }
|
10
|
+
let(:html_content) { Template['fixtures/html_content'] }
|
11
|
+
let(:attributes_helper) { Template['fixtures/attributes_helper'] }
|
12
|
+
|
13
|
+
it "should be defined by filename on Template namespace" do
|
14
|
+
expect(simple).to be_kind_of(Template)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should render using #render" do
|
18
|
+
expect(simple.render(self)).to include('lol')
|
19
|
+
end
|
20
|
+
|
21
|
+
it "accepts a context to render template with" do
|
22
|
+
@haml_message = "hello world"
|
23
|
+
expect(advanced.render(self)).to include('hello world')
|
24
|
+
expect([
|
25
|
+
%{hello world<a bar='baz' href='#' foo='123' quz='1134'>foofoofoo</a>}, # haml 4
|
26
|
+
%{hello world<a bar='baz' foo='123' href='#' quz='1134'>foofoofoo</a>}, # haml 5
|
27
|
+
]).to include(advanced.render(self))
|
28
|
+
end
|
29
|
+
|
30
|
+
it "generates html with a given context" do
|
31
|
+
@h1_content = 'Ford Perfect'
|
32
|
+
expect(html_content.render(self)).to include('<h1>Ford Perfect</h1>')
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'can generates attributes' do
|
36
|
+
require 'ostruct'
|
37
|
+
note = Struct.new(:name, :note_class)
|
38
|
+
@keyboard = OpenStruct.new(notes: [note.new(:C, :sharp), note.new(:F, :sharp)])
|
39
|
+
expect([
|
40
|
+
"<div class='keyboard'>"+
|
41
|
+
"<div class='octave'>"+
|
42
|
+
"<a class='4 key'></a><div class='key sharp'><div class='name'>C</div></div>"+
|
43
|
+
"<a class='4 key'></a><div class='key sharp'><div class='name'>F</div></div>"+
|
44
|
+
"</div><div class='octave'>"+
|
45
|
+
"<a class='4 key'></a><div class='key sharp'><div class='name'>C</div></div>"+
|
46
|
+
"<a class='4 key'></a><div class='key sharp'><div class='name'>F</div></div>"+
|
47
|
+
"</div>"+
|
48
|
+
"</div>",
|
49
|
+
"<div class='keyboard'>"+
|
50
|
+
"<div class='octave'>"+
|
51
|
+
"<a class='key 4'></a><div class='key sharp'><div class='name'>C</div></div>"+
|
52
|
+
"<a class='key 4'></a><div class='key sharp'><div class='name'>F</div></div>"+
|
53
|
+
"</div><div class='octave'>"+
|
54
|
+
"<a class='key 4'></a><div class='key sharp'><div class='name'>C</div></div>"+
|
55
|
+
"<a class='key 4'></a><div class='key sharp'><div class='name'>F</div></div>"+
|
56
|
+
"</div>"+
|
57
|
+
"</div>"
|
58
|
+
]).to include(attributes_helper.render(self))
|
59
|
+
end
|
60
|
+
end
|
File without changes
|
metadata
CHANGED
@@ -1,29 +1,49 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opal-haml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Beynon
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-12-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: opal
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.10'
|
20
|
+
- - "<"
|
18
21
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
22
|
+
version: '2'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- - "
|
27
|
+
- - ">="
|
25
28
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.10
|
29
|
+
version: '0.10'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '2'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: opal-sprockets
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 0.5.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.5.0
|
27
47
|
- !ruby/object:Gem::Dependency
|
28
48
|
name: haml
|
29
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -42,16 +62,16 @@ dependencies:
|
|
42
62
|
name: opal-rspec
|
43
63
|
requirement: !ruby/object:Gem::Requirement
|
44
64
|
requirements:
|
45
|
-
- - "
|
65
|
+
- - ">="
|
46
66
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0
|
67
|
+
version: '0'
|
48
68
|
type: :development
|
49
69
|
prerelease: false
|
50
70
|
version_requirements: !ruby/object:Gem::Requirement
|
51
71
|
requirements:
|
52
|
-
- - "
|
72
|
+
- - ">="
|
53
73
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0
|
74
|
+
version: '0'
|
55
75
|
- !ruby/object:Gem::Dependency
|
56
76
|
name: rake
|
57
77
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,32 +92,34 @@ executables: []
|
|
72
92
|
extensions: []
|
73
93
|
extra_rdoc_files: []
|
74
94
|
files:
|
95
|
+
- ".github/workflows/build.yml"
|
75
96
|
- ".gitignore"
|
76
|
-
- ".travis.yml"
|
77
97
|
- CHANGELOG.md
|
78
98
|
- Gemfile
|
79
99
|
- LICENSE
|
80
100
|
- README.md
|
81
101
|
- Rakefile
|
82
102
|
- config.ru
|
103
|
+
- lib-opal/haml/attribute_builder.rb
|
104
|
+
- lib-opal/opal-haml.rb
|
83
105
|
- lib/opal-haml.rb
|
84
106
|
- lib/opal/haml.rb
|
85
107
|
- lib/opal/haml/builder.rb
|
86
108
|
- lib/opal/haml/processor.rb
|
87
109
|
- lib/opal/haml/version.rb
|
88
110
|
- opal-haml.gemspec
|
89
|
-
- opal/
|
90
|
-
- spec/
|
91
|
-
- spec/
|
92
|
-
- spec/
|
93
|
-
- spec/
|
94
|
-
- spec/
|
95
|
-
- spec/spec_helper.rb
|
96
|
-
homepage:
|
111
|
+
- spec-opal/fixtures/advanced.haml
|
112
|
+
- spec-opal/fixtures/attributes_helper.haml
|
113
|
+
- spec-opal/fixtures/html_content.haml
|
114
|
+
- spec-opal/fixtures/simple.haml
|
115
|
+
- spec-opal/haml_spec.rb
|
116
|
+
- spec-opal/output_buffer_spec.rb
|
117
|
+
- spec-opal/spec_helper.rb
|
118
|
+
homepage: https://github.com/opal/opal-haml#readme
|
97
119
|
licenses:
|
98
120
|
- MIT
|
99
121
|
metadata: {}
|
100
|
-
post_install_message:
|
122
|
+
post_install_message:
|
101
123
|
rdoc_options: []
|
102
124
|
require_paths:
|
103
125
|
- lib
|
@@ -112,15 +134,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
112
134
|
- !ruby/object:Gem::Version
|
113
135
|
version: '0'
|
114
136
|
requirements: []
|
115
|
-
|
116
|
-
|
117
|
-
signing_key:
|
137
|
+
rubygems_version: 3.2.22
|
138
|
+
signing_key:
|
118
139
|
specification_version: 4
|
119
140
|
summary: Run Haml templates client-side with Opal
|
120
|
-
test_files:
|
121
|
-
- spec/advanced.haml
|
122
|
-
- spec/haml_spec.rb
|
123
|
-
- spec/html_content.haml
|
124
|
-
- spec/output_buffer_spec.rb
|
125
|
-
- spec/simple.haml
|
126
|
-
- spec/spec_helper.rb
|
141
|
+
test_files: []
|
data/.travis.yml
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
sudo: false
|
3
|
-
rvm: 2.3.4
|
4
|
-
|
5
|
-
|
6
|
-
env:
|
7
|
-
- HAML_VERSION="~> 4.0" OPAL_VERSION='~> 0.10.0'
|
8
|
-
- HAML_VERSION="~> 5.0" OPAL_VERSION='~> 0.10.0'
|
9
|
-
- HAML_VERSION="~> 4.0" OPAL_VERSION='~> 0.11.0.rc1'
|
10
|
-
- HAML_VERSION="~> 5.0" OPAL_VERSION='~> 0.11.0.rc1'
|
11
|
-
|
12
|
-
cache:
|
13
|
-
bundler: true
|
14
|
-
directories:
|
15
|
-
- node_modules
|
16
|
-
- phantom20
|
17
|
-
|
18
|
-
before_install:
|
19
|
-
# Attempt to work around Travis issues and Ruby 2.3 - https://github.com/vcr/vcr/issues/582
|
20
|
-
- gem update --system
|
21
|
-
- "mkdir -p phantom20"
|
22
|
-
- "export PATH=`pwd`/phantom20:$PATH"
|
23
|
-
- "echo $PATH"
|
24
|
-
- "pushd phantom20"
|
25
|
-
- "ls phantomjs || curl -L -O https://s3.amazonaws.com/travis-phantomjs/phantomjs-2.0.0-ubuntu-12.04.tar.bz2"
|
26
|
-
- "ls phantomjs || tar xjvf phantomjs-2.0.0-ubuntu-12.04.tar.bz2"
|
27
|
-
- "rm -rf phantomjs-2.0.0-ubuntu-12.04.tar.bz2"
|
28
|
-
- "popd"
|
29
|
-
|
30
|
-
|
data/spec/haml_spec.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require File.expand_path('../simple', __FILE__)
|
3
|
-
require File.expand_path('../advanced', __FILE__)
|
4
|
-
require File.expand_path('../html_content', __FILE__)
|
5
|
-
|
6
|
-
describe "Haml files" do
|
7
|
-
let(:simple) { Template['simple'] }
|
8
|
-
let(:advanced) { Template['advanced'] }
|
9
|
-
let(:html_content) { Template['html_content'] }
|
10
|
-
|
11
|
-
it "should be defined by filename on Template namespace" do
|
12
|
-
expect(simple).to be_kind_of(Template)
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should render using #render" do
|
16
|
-
expect(simple.render(self)).to include('lol')
|
17
|
-
end
|
18
|
-
|
19
|
-
it "accepts a context to render template with" do
|
20
|
-
@haml_message = "hello world"
|
21
|
-
expect(advanced.render(self)).to include('hello world')
|
22
|
-
expect([
|
23
|
-
%{hello world<a bar='baz' href='#' foo='123' quz='1134'>foofoofoo</a>}, # haml 4
|
24
|
-
%{hello world<a bar='baz' foo='123' href='#' quz='1134'>foofoofoo</a>}, # haml 5
|
25
|
-
]).to include(advanced.render(self))
|
26
|
-
end
|
27
|
-
|
28
|
-
it "generates html with a given context" do
|
29
|
-
@h1_content = 'Ford Perfect'
|
30
|
-
expect(html_content.render(self)).to include('<h1>Ford Perfect</h1>')
|
31
|
-
end
|
32
|
-
end
|
data/spec/spec_helper.rb
DELETED