opal-haml 0.2.0 → 0.3.0

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
  SHA1:
3
- metadata.gz: 3b0af2dad04a9fd95b530e40a2a9d9881c606d41
4
- data.tar.gz: 9707c8f743296cd31e73fe52d3a7458f1bd9c7fd
3
+ metadata.gz: 305b113a6fa5548f1271669bd052274214b8f7f9
4
+ data.tar.gz: 6cc024e7ba8431aefb07c7c9626f83602e2cd951
5
5
  SHA512:
6
- metadata.gz: 5c6e3a530c8e0447680380024e732e69818dd6d62b4d55ba9fd8bfc884a363c042e33c1bdaa69a0b2348c66eb84c48f59b579ef9d34cd19cd96590a83e62d7fd
7
- data.tar.gz: 546cc1182c53f4f2d4b723ff4c6a6597e24df0f97be32d6d535d028997de8039ab519d4b6f486a8c86d688d24cf0d71392bccaed775bfcc9198bc20e4399cdd1
6
+ metadata.gz: bd48d21852e5aacb70297f5377e6703fdd1df259b6f94b4e8d14a092e854ab9d43aa35a15689bc51ea96f024eef9d37fc575664215c5a621e94b4ede7dadafb7
7
+ data.tar.gz: 186b45f6dff3b65a3bbfdf83375d56497b195a868314ece2b6de7a125f099ce2262fd22651f2b4052f7a9e4ed03cff2a8a5c7713f53e76070c00bdd9d4657165
data/CHANGELOG.md CHANGED
@@ -1,7 +1,15 @@
1
+ ## 0.3.0 2015-02-03
2
+
3
+ * Add support for new opal Builder processors.
4
+
5
+ * Implicitly require `opal-haml` when any haml template is required
6
+
7
+ * Cleanup generated code to be use Opal ERB runtime directly
8
+
1
9
  ## 0.2.0 2013-12-17
2
10
 
3
- * Remove opal-sprockets dependency
11
+ * Remove opal-sprockets dependency
4
12
 
5
13
  ## 0.1.0 2013-12-17
6
14
 
7
- * Initial release
15
+ * Initial release
data/Gemfile CHANGED
@@ -1,4 +1,2 @@
1
1
  source 'https://rubygems.org'
2
2
  gemspec
3
-
4
- gem 'opal', '~> 0.5.0'
data/README.md CHANGED
@@ -1,6 +1,19 @@
1
- # opal-haml
1
+ # opal-haml: Haml templates for opal
2
2
 
3
- Haml templates for opal
3
+ This gem adds `.haml` files to sprockets to precompile templates for opal. This
4
+ gem does not make the haml compiler available under opal, just the result of
5
+ pre-compiling a haml template.
6
+
7
+ A small runtime is included to handle dynamic attributes, as well as allowing
8
+ content to be rendered.
9
+
10
+ All haml templates become available under the `Template` constant in Opal,
11
+ which allows a template to be easily rendered in a context:
12
+
13
+ ```ruby
14
+ Template['user'].render(my_user)
15
+ # => <div>..</div>
16
+ ```
4
17
 
5
18
  ## Usage
6
19
 
@@ -30,11 +43,11 @@ class User
30
43
  attr_accessor :name, :age
31
44
 
32
45
  def initialize(name, age)
33
- @name, @age = name age
46
+ @name, @age = name, age
34
47
  end
35
48
  end
36
49
 
37
- user = User.new('Ford Perfect', 42)
50
+ user = User.new('Ford Prefect', 42)
38
51
  html = Template['user_template'].render(user)
39
52
  puts html
40
53
  # => <div class="row">...</div>
@@ -54,6 +67,12 @@ Run tests using opal-rspec:
54
67
  $ bundle exec rake
55
68
  ```
56
69
 
70
+ Run specs in the browser:
71
+
72
+ ```
73
+ $ bundle exec rackup
74
+ ```
75
+
57
76
  ## License
58
77
 
59
78
  (The MIT License)
@@ -0,0 +1,25 @@
1
+ require 'opal/builder_processors'
2
+
3
+ module Opal
4
+ module Haml
5
+ class HamlProcessor < Opal::BuilderProcessors::RubyProcessor
6
+ handles :haml
7
+
8
+ def initialize(*args)
9
+ super
10
+ @source = prepare(@source, @filename)
11
+ end
12
+
13
+ def requires
14
+ ['opal-haml'] + super
15
+ end
16
+
17
+ def prepare(source, path)
18
+ haml = ::Haml::Engine.new(source, :ugly => true).precompiled
19
+ haml = haml.gsub('_hamlout.buffer', '_hamlout')
20
+
21
+ ::Opal::Haml.wrap haml, path
22
+ end
23
+ end
24
+ end
25
+ end
@@ -17,8 +17,9 @@ module Opal
17
17
  def prepare
18
18
  end
19
19
 
20
- def evaluate(scope, locals, &block)
21
- Opal::Haml.compile data, scope.logical_path.sub(/^templates\//, '')
20
+ def evaluate(context, locals, &block)
21
+ context.require_asset 'opal-haml'
22
+ Opal::Haml.compile data, context.logical_path.sub(/^templates\//, '')
22
23
  end
23
24
  end
24
25
  end
@@ -1,5 +1,5 @@
1
1
  module Opal
2
2
  module Haml
3
- VERSION = '0.2.0'
3
+ VERSION = '0.3.0'
4
4
  end
5
5
  end
data/lib/opal/haml.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'opal'
2
+ require 'opal/haml/builder'
2
3
  require 'opal/haml/processor'
3
4
  require 'opal/haml/version'
4
5
 
@@ -6,11 +7,17 @@ module Opal
6
7
  module Haml
7
8
  def self.compile(source, file = '(haml)')
8
9
  haml = ::Haml::Engine.new(source, :ugly => true).precompiled
10
+ haml = haml.gsub('_hamlout.buffer', '_hamlout')
9
11
  Opal.compile(wrap(haml, file))
10
12
  end
11
13
 
12
14
  def self.wrap(haml, file)
13
- "Template.new('#{file}') do |_hamlout|\n#{haml}\n_hamlout.join\nend\n"
15
+ <<-EOS
16
+ Template.new('#{file}') do |_hamlout|
17
+ #{haml}
18
+ _hamlout.join
19
+ end
20
+ EOS
14
21
  end
15
22
  end
16
23
  end
data/opal/opal-haml.rb CHANGED
@@ -2,10 +2,6 @@ require 'template'
2
2
 
3
3
  class Template
4
4
  class OutputBuffer
5
- def buffer
6
- self
7
- end
8
-
9
5
  alias << append
10
6
 
11
7
  # allow tags in haml to have dynamic attributes
data/opal-haml.gemspec CHANGED
@@ -20,6 +20,6 @@ Gem::Specification.new do |s|
20
20
  s.add_dependency 'opal', ['>= 0.5.0', '< 1.0.0']
21
21
  s.add_dependency 'haml'
22
22
 
23
- s.add_development_dependency 'opal-rspec', '>= 0.2.1'
23
+ s.add_development_dependency 'opal-rspec', '~> 0.4.0'
24
24
  s.add_development_dependency 'rake'
25
25
  end
data/spec/haml_spec.rb CHANGED
@@ -1,5 +1,4 @@
1
- require 'opal-haml'
2
-
1
+ require 'spec_helper'
3
2
  require File.expand_path('../simple', __FILE__)
4
3
  require File.expand_path('../advanced', __FILE__)
5
4
  require File.expand_path('../html_content', __FILE__)
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+ require 'template'
3
+
4
+ describe Template::OutputBuffer do
5
+ describe "#attributes" do
6
+ it "compiles an empty attribute set as ''" do
7
+ attributes({}).should == ""
8
+ end
9
+
10
+ it "can compile simple attributes" do
11
+ result = attributes(name: 'foo', height: '100')
12
+ expect(result).to include("name='foo'", "height='100'")
13
+ end
14
+
15
+ it "skips the attribute for false values" do
16
+ result = attributes(name: false)
17
+ expect(result).to_not include('name')
18
+ end
19
+
20
+ it "generates a simple named attribute for true values" do
21
+ result = attributes(closable: true)
22
+ expect(result).to include('closable')
23
+ expect(result).to_not include('closable=')
24
+ end
25
+
26
+ def attributes(attrs)
27
+ subject.attributes({}, nil, attrs)
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,2 @@
1
+ require 'opal'
2
+ require 'opal-haml'
metadata CHANGED
@@ -1,75 +1,75 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opal-haml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Beynon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-17 00:00:00.000000000 Z
11
+ date: 2015-02-03 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
18
  - !ruby/object:Gem::Version
19
19
  version: 0.5.0
20
- - - <
20
+ - - "<"
21
21
  - !ruby/object:Gem::Version
22
22
  version: 1.0.0
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
- - - '>='
27
+ - - ">="
28
28
  - !ruby/object:Gem::Version
29
29
  version: 0.5.0
30
- - - <
30
+ - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: 1.0.0
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: haml
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - '>='
37
+ - - ">="
38
38
  - !ruby/object:Gem::Version
39
39
  version: '0'
40
40
  type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
- - - '>='
44
+ - - ">="
45
45
  - !ruby/object:Gem::Version
46
46
  version: '0'
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: opal-rspec
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
- - - '>='
51
+ - - "~>"
52
52
  - !ruby/object:Gem::Version
53
- version: 0.2.1
53
+ version: 0.4.0
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
- - - '>='
58
+ - - "~>"
59
59
  - !ruby/object:Gem::Version
60
- version: 0.2.1
60
+ version: 0.4.0
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: rake
63
63
  requirement: !ruby/object:Gem::Requirement
64
64
  requirements:
65
- - - '>='
65
+ - - ">="
66
66
  - !ruby/object:Gem::Version
67
67
  version: '0'
68
68
  type: :development
69
69
  prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
- - - '>='
72
+ - - ">="
73
73
  - !ruby/object:Gem::Version
74
74
  version: '0'
75
75
  description: Run Haml templates client-side with Opal.
@@ -78,7 +78,7 @@ executables: []
78
78
  extensions: []
79
79
  extra_rdoc_files: []
80
80
  files:
81
- - .gitignore
81
+ - ".gitignore"
82
82
  - CHANGELOG.md
83
83
  - Gemfile
84
84
  - LICENSE
@@ -87,6 +87,7 @@ files:
87
87
  - config.ru
88
88
  - lib/opal-haml.rb
89
89
  - lib/opal/haml.rb
90
+ - lib/opal/haml/builder.rb
90
91
  - lib/opal/haml/processor.rb
91
92
  - lib/opal/haml/version.rb
92
93
  - opal-haml.gemspec
@@ -94,7 +95,9 @@ files:
94
95
  - spec/advanced.haml
95
96
  - spec/haml_spec.rb
96
97
  - spec/html_content.haml
98
+ - spec/output_buffer_spec.rb
97
99
  - spec/simple.haml
100
+ - spec/spec_helper.rb
98
101
  homepage: http://opalrb.org
99
102
  licenses:
100
103
  - MIT
@@ -105,17 +108,17 @@ require_paths:
105
108
  - lib
106
109
  required_ruby_version: !ruby/object:Gem::Requirement
107
110
  requirements:
108
- - - '>='
111
+ - - ">="
109
112
  - !ruby/object:Gem::Version
110
113
  version: '0'
111
114
  required_rubygems_version: !ruby/object:Gem::Requirement
112
115
  requirements:
113
- - - '>='
116
+ - - ">="
114
117
  - !ruby/object:Gem::Version
115
118
  version: '0'
116
119
  requirements: []
117
120
  rubyforge_project:
118
- rubygems_version: 2.1.9
121
+ rubygems_version: 2.4.5
119
122
  signing_key:
120
123
  specification_version: 4
121
124
  summary: Run Haml templates client-side with Opal
@@ -123,4 +126,7 @@ test_files:
123
126
  - spec/advanced.haml
124
127
  - spec/haml_spec.rb
125
128
  - spec/html_content.haml
129
+ - spec/output_buffer_spec.rb
126
130
  - spec/simple.haml
131
+ - spec/spec_helper.rb
132
+ has_rdoc: