opal-haml 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3b0af2dad04a9fd95b530e40a2a9d9881c606d41
4
+ data.tar.gz: 9707c8f743296cd31e73fe52d3a7458f1bd9c7fd
5
+ SHA512:
6
+ metadata.gz: 5c6e3a530c8e0447680380024e732e69818dd6d62b4d55ba9fd8bfc884a363c042e33c1bdaa69a0b2348c66eb84c48f59b579ef9d34cd19cd96590a83e62d7fd
7
+ data.tar.gz: 546cc1182c53f4f2d4b723ff4c6a6597e24df0f97be32d6d535d028997de8039ab519d4b6f486a8c86d688d24cf0d71392bccaed775bfcc9198bc20e4399cdd1
@@ -0,0 +1,3 @@
1
+ .DS_Store
2
+ Gemfile.lock
3
+ *.gem
@@ -0,0 +1,7 @@
1
+ ## 0.2.0 2013-12-17
2
+
3
+ * Remove opal-sprockets dependency
4
+
5
+ ## 0.1.0 2013-12-17
6
+
7
+ * Initial release
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+
4
+ gem 'opal', '~> 0.5.0'
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ (The MIT License)
2
+
3
+ Copyright (C) 2013 by Adam Beynon
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,79 @@
1
+ # opal-haml
2
+
3
+ Haml templates for opal
4
+
5
+ ## Usage
6
+
7
+ Add opal-haml to your `Gemfile`:
8
+
9
+ ```ruby
10
+ gem 'opal-haml', :github => 'opal/opal-haml'
11
+ ```
12
+
13
+ Create a haml file in the opal load path (e.g. `app/user_template.haml`):
14
+
15
+ ```haml
16
+ .row
17
+ .col-md-6
18
+ = self.name
19
+ .col-md-6
20
+ = self.age
21
+ ```
22
+
23
+ Render the haml template:
24
+
25
+ ```ruby
26
+ # app/application.rb
27
+ require 'user_template'
28
+
29
+ class User
30
+ attr_accessor :name, :age
31
+
32
+ def initialize(name, age)
33
+ @name, @age = name age
34
+ end
35
+ end
36
+
37
+ user = User.new('Ford Perfect', 42)
38
+ html = Template['user_template'].render(user)
39
+ puts html
40
+ # => <div class="row">...</div>
41
+ ```
42
+
43
+ ## Running tests
44
+
45
+ Get dependencies:
46
+
47
+ ```
48
+ $ bundle install
49
+ ```
50
+
51
+ Run tests using opal-rspec:
52
+
53
+ ```
54
+ $ bundle exec rake
55
+ ```
56
+
57
+ ## License
58
+
59
+ (The MIT License)
60
+
61
+ Copyright (C) 2013 by Adam Beynon
62
+
63
+ Permission is hereby granted, free of charge, to any person obtaining a copy
64
+ of this software and associated documentation files (the "Software"), to deal
65
+ in the Software without restriction, including without limitation the rights
66
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
67
+ copies of the Software, and to permit persons to whom the Software is
68
+ furnished to do so, subject to the following conditions:
69
+
70
+ The above copyright notice and this permission notice shall be included in
71
+ all copies or substantial portions of the Software.
72
+
73
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
74
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
75
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
76
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
77
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
78
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
79
+ THE SOFTWARE.
@@ -0,0 +1,5 @@
1
+ require 'bundler'
2
+ Bundler.require
3
+
4
+ require 'opal/rspec/rake_task'
5
+ Opal::RSpec::RakeTask.new(:default)
@@ -0,0 +1,10 @@
1
+ require 'bundler'
2
+ Bundler.require
3
+
4
+ require 'opal-rspec'
5
+
6
+ run Opal::Server.new { |s|
7
+ s.main = 'opal/rspec/sprockets_runner'
8
+ s.append_path 'spec'
9
+ s.debug = true
10
+ }
@@ -0,0 +1 @@
1
+ require 'opal/haml'
@@ -0,0 +1,18 @@
1
+ require 'opal'
2
+ require 'opal/haml/processor'
3
+ require 'opal/haml/version'
4
+
5
+ module Opal
6
+ module Haml
7
+ def self.compile(source, file = '(haml)')
8
+ haml = ::Haml::Engine.new(source, :ugly => true).precompiled
9
+ Opal.compile(wrap(haml, file))
10
+ end
11
+
12
+ def self.wrap(haml, file)
13
+ "Template.new('#{file}') do |_hamlout|\n#{haml}\n_hamlout.join\nend\n"
14
+ end
15
+ end
16
+ end
17
+
18
+ Opal.append_path File.expand_path('../../../opal', __FILE__).untaint
@@ -0,0 +1,27 @@
1
+ require 'haml'
2
+ require 'sprockets'
3
+
4
+ module Opal
5
+ module Haml
6
+ class Processor < Tilt::Template
7
+ self.default_mime_type = 'application/javascript'
8
+
9
+ def self.engine_initialized?
10
+ true
11
+ end
12
+
13
+ def initialize_engine
14
+ require_template_library 'opal'
15
+ end
16
+
17
+ def prepare
18
+ end
19
+
20
+ def evaluate(scope, locals, &block)
21
+ Opal::Haml.compile data, scope.logical_path.sub(/^templates\//, '')
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+ Sprockets.register_engine '.haml', Opal::Haml::Processor
@@ -0,0 +1,5 @@
1
+ module Opal
2
+ module Haml
3
+ VERSION = '0.2.0'
4
+ end
5
+ end
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $LOAD_PATH << File.expand_path('../lib', __FILE__)
3
+ require 'opal/haml/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'opal-haml'
7
+ s.version = Opal::Haml::VERSION
8
+ s.author = 'Adam Beynon'
9
+ s.email = 'adam@adambeynon.com'
10
+ s.homepage = 'http://opalrb.org'
11
+ s.summary = 'Run Haml templates client-side with Opal'
12
+ s.description = 'Run Haml templates client-side with Opal.'
13
+ s.license = 'MIT'
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.require_paths = ['lib']
19
+
20
+ s.add_dependency 'opal', ['>= 0.5.0', '< 1.0.0']
21
+ s.add_dependency 'haml'
22
+
23
+ s.add_development_dependency 'opal-rspec', '>= 0.2.1'
24
+ s.add_development_dependency 'rake'
25
+ end
@@ -0,0 +1,32 @@
1
+ require 'template'
2
+
3
+ class Template
4
+ class OutputBuffer
5
+ def buffer
6
+ self
7
+ end
8
+
9
+ alias << append
10
+
11
+ # allow tags in haml to have dynamic attributes
12
+ def attributes(class_id, obj_ref, *attributes_hashes)
13
+ attributes = class_id
14
+
15
+ attributes_hashes.each do |hash|
16
+ attributes.update hash
17
+ end
18
+
19
+ result = attributes.collect do |attr, value|
20
+ if value == true
21
+ next " #{attr}"
22
+ elsif value == false
23
+ next
24
+ else
25
+ " #{attr}='#{value}'"
26
+ end
27
+ end
28
+
29
+ result.join
30
+ end
31
+ end
32
+ end
@@ -0,0 +1 @@
1
+ = @haml_message
@@ -0,0 +1,29 @@
1
+ require 'opal-haml'
2
+
3
+ require File.expand_path('../simple', __FILE__)
4
+ require File.expand_path('../advanced', __FILE__)
5
+ require File.expand_path('../html_content', __FILE__)
6
+
7
+ describe "Haml files" do
8
+ let(:simple) { Template['simple'] }
9
+ let(:advanced) { Template['advanced'] }
10
+ let(:html_content) { Template['html_content'] }
11
+
12
+ it "should be defined by filename on Template namespace" do
13
+ expect(simple).to be_kind_of(Template)
14
+ end
15
+
16
+ it "should render using #render" do
17
+ expect(simple.render(self)).to include('lol')
18
+ end
19
+
20
+ it "accepts a context to render template with" do
21
+ @haml_message = "hello world"
22
+ expect(advanced.render(self)).to include('hello world')
23
+ end
24
+
25
+ it "generates html with a given context" do
26
+ @h1_content = 'Ford Perfect'
27
+ expect(html_content.render(self)).to include('<h1>Ford Perfect</h1>')
28
+ end
29
+ end
@@ -0,0 +1 @@
1
+ %h1= @h1_content
@@ -0,0 +1 @@
1
+ lol
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: opal-haml
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Adam Beynon
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: opal
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.5.0
20
+ - - <
21
+ - !ruby/object:Gem::Version
22
+ version: 1.0.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 0.5.0
30
+ - - <
31
+ - !ruby/object:Gem::Version
32
+ version: 1.0.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: haml
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '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'
47
+ - !ruby/object:Gem::Dependency
48
+ name: opal-rspec
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - '>='
52
+ - !ruby/object:Gem::Version
53
+ version: 0.2.1
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - '>='
59
+ - !ruby/object:Gem::Version
60
+ version: 0.2.1
61
+ - !ruby/object:Gem::Dependency
62
+ name: rake
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ description: Run Haml templates client-side with Opal.
76
+ email: adam@adambeynon.com
77
+ executables: []
78
+ extensions: []
79
+ extra_rdoc_files: []
80
+ files:
81
+ - .gitignore
82
+ - CHANGELOG.md
83
+ - Gemfile
84
+ - LICENSE
85
+ - README.md
86
+ - Rakefile
87
+ - config.ru
88
+ - lib/opal-haml.rb
89
+ - lib/opal/haml.rb
90
+ - lib/opal/haml/processor.rb
91
+ - lib/opal/haml/version.rb
92
+ - opal-haml.gemspec
93
+ - opal/opal-haml.rb
94
+ - spec/advanced.haml
95
+ - spec/haml_spec.rb
96
+ - spec/html_content.haml
97
+ - spec/simple.haml
98
+ homepage: http://opalrb.org
99
+ licenses:
100
+ - MIT
101
+ metadata: {}
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project:
118
+ rubygems_version: 2.1.9
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: Run Haml templates client-side with Opal
122
+ test_files:
123
+ - spec/advanced.haml
124
+ - spec/haml_spec.rb
125
+ - spec/html_content.haml
126
+ - spec/simple.haml