opal-haml 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +30 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile +1 -0
- data/README.md +3 -1
- data/lib/opal/haml.rb +9 -1
- data/lib/opal/haml/builder.rb +1 -4
- data/lib/opal/haml/version.rb +1 -1
- data/opal/opal-haml.rb +29 -0
- data/spec/advanced.haml +1 -0
- data/spec/haml_spec.rb +4 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1419033dec6d3a72ed09a3011ecc454551406271
|
4
|
+
data.tar.gz: '02064278322c4b072f766465870a035cc4724ad5'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c66562091ba037ecbead72df0a925044e129c65a2d8d31965cd4a0293bdfa7935614630335b6f4c45577f949b3e903a4a532ff74efc139ad603cbe982866977
|
7
|
+
data.tar.gz: 9c7de3fd306c703c012ee02992339cff80df33b18042aca33bc3ab535f2f43effd18cb38da334de2b1c00d68ec6f824942fdfa9129f4ef7e63690921f9669a76
|
data/.travis.yml
ADDED
@@ -0,0 +1,30 @@
|
|
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/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# opal-haml: Haml templates for opal
|
2
2
|
|
3
|
+
[![Build Status](https://travis-ci.org/opal/opal-haml.svg?branch=master)](https://travis-ci.org/opal/opal-haml)
|
4
|
+
|
3
5
|
This gem adds `.haml` files to sprockets to precompile templates for opal. This
|
4
6
|
gem does not make the haml compiler available under opal, just the result of
|
5
7
|
pre-compiling a haml template.
|
@@ -20,7 +22,7 @@ Template['user'].render(my_user)
|
|
20
22
|
Add opal-haml to your `Gemfile`:
|
21
23
|
|
22
24
|
```ruby
|
23
|
-
gem 'opal-haml'
|
25
|
+
gem 'opal-haml'
|
24
26
|
```
|
25
27
|
|
26
28
|
Create a haml file in the opal load path (e.g. `app/user_template.haml`):
|
data/lib/opal/haml.rb
CHANGED
@@ -5,12 +5,19 @@ require 'opal/haml/version'
|
|
5
5
|
|
6
6
|
module Opal
|
7
7
|
module Haml
|
8
|
+
haml_major_version = ::Haml::VERSION.to_i
|
9
|
+
@options = if haml_major_version > 4
|
10
|
+
{freeze_static: false, remove_whitespace: true}
|
11
|
+
else
|
12
|
+
{freeze_static: false, remove_whitespace: true, ugly: true}
|
13
|
+
end.freeze
|
14
|
+
|
8
15
|
def self.compile(source, file = '(haml)')
|
9
16
|
Opal.compile(compile_haml(source, file))
|
10
17
|
end
|
11
18
|
|
12
19
|
def self.compile_haml(source, file)
|
13
|
-
haml = ::Haml::Engine.new(source,
|
20
|
+
haml = ::Haml::Engine.new(source, @options).precompiled
|
14
21
|
haml = haml.gsub('_hamlout.buffer', '_hamlout')
|
15
22
|
wrap(haml, file)
|
16
23
|
end
|
@@ -19,6 +26,7 @@ module Opal
|
|
19
26
|
<<-EOS
|
20
27
|
require 'opal-haml'
|
21
28
|
Template.new('#{file}') do |_hamlout|
|
29
|
+
_hamlout.extend Haml::Buffer
|
22
30
|
#{haml}
|
23
31
|
_hamlout.join
|
24
32
|
end
|
data/lib/opal/haml/builder.rb
CHANGED
@@ -15,10 +15,7 @@ module Opal
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def prepare(source, path)
|
18
|
-
|
19
|
-
haml = haml.gsub('_hamlout.buffer', '_hamlout')
|
20
|
-
|
21
|
-
::Opal::Haml.wrap haml, path
|
18
|
+
::Opal::Haml.compile_haml(source, path)
|
22
19
|
end
|
23
20
|
end
|
24
21
|
end
|
data/lib/opal/haml/version.rb
CHANGED
data/opal/opal-haml.rb
CHANGED
@@ -1,5 +1,34 @@
|
|
1
1
|
require 'template'
|
2
2
|
|
3
|
+
module Haml
|
4
|
+
module Buffer
|
5
|
+
def rstrip!
|
6
|
+
self
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
module Helpers
|
11
|
+
def self.html_escape(string)
|
12
|
+
# http://stackoverflow.com/a/9756789
|
13
|
+
%x{
|
14
|
+
return ('' + string) /* Forces the conversion to string. */
|
15
|
+
.replace(/&/g, '&') /* This MUST be the 1st replacement. */
|
16
|
+
.replace(/'/g, ''') /* The 4 other predefined entities, required. */
|
17
|
+
.replace(/"/g, '"')
|
18
|
+
.replace(/</g, '<')
|
19
|
+
.replace(/>/g, '>')
|
20
|
+
/*
|
21
|
+
You may add other replacements here for HTML only
|
22
|
+
(but it's not necessary).
|
23
|
+
Or for XML, only if the named entities are defined in its DTD.
|
24
|
+
*/
|
25
|
+
.replace(/\r\n/g, ' ') /* Must be before the next replacement. */
|
26
|
+
.replace(/[\r\n]/g, ' ');
|
27
|
+
}
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
3
32
|
class Template
|
4
33
|
class OutputBuffer
|
5
34
|
alias << append
|
data/spec/advanced.haml
CHANGED
data/spec/haml_spec.rb
CHANGED
@@ -19,6 +19,10 @@ describe "Haml files" do
|
|
19
19
|
it "accepts a context to render template with" do
|
20
20
|
@haml_message = "hello world"
|
21
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))
|
22
26
|
end
|
23
27
|
|
24
28
|
it "generates html with a given context" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opal-haml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Beynon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-05-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: opal
|
@@ -73,6 +73,7 @@ extensions: []
|
|
73
73
|
extra_rdoc_files: []
|
74
74
|
files:
|
75
75
|
- ".gitignore"
|
76
|
+
- ".travis.yml"
|
76
77
|
- CHANGELOG.md
|
77
78
|
- Gemfile
|
78
79
|
- LICENSE
|
@@ -112,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
112
113
|
version: '0'
|
113
114
|
requirements: []
|
114
115
|
rubyforge_project:
|
115
|
-
rubygems_version: 2.6.
|
116
|
+
rubygems_version: 2.6.8
|
116
117
|
signing_key:
|
117
118
|
specification_version: 4
|
118
119
|
summary: Run Haml templates client-side with Opal
|