opal-slim 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2a6ac1d70c0611a5e07bc95eb4af2eaf7953ad37
4
+ data.tar.gz: 95876d3f070c5a271df1ea674e737bd7a412a3a2
5
+ SHA512:
6
+ metadata.gz: 32e9f60d13a90689b6552eee8e27cbed07d522aad838e021317568e7359be1cf34c0e3a68c48a95c0c07fc83ca9140cde55afedc7fdd72a7637eec3382acaec0
7
+ data.tar.gz: 29f972cb695c15b275c6c5975d3d7fa18cfebcc95e313deacd4e538216b161bd7f826e30be4a9702122f31e6fb60f06e3bedb38dc545d5fd5c73c24158b3bf8f
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in opal-slim.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Jamie Gaskins
2
+
3
+ MIT License
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.
@@ -0,0 +1,23 @@
1
+ # Opal-Slim
2
+
3
+ Opal-Slim is a set of Opal bindings for the Slim templating language, allowing you to use Slim templates in your Opal app. It was written to work with the [Clearwater framework](https://github.com/jgaskins/clearwater), but it should work just fine with any Opal app.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'opal-slim', github: 'jgaskins/opal-slim'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ ## Contributing
18
+
19
+ 1. Fork it ( https://github.com/[my-github-username]/opal-slim/fork )
20
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
21
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
22
+ 4. Push to the branch (`git push origin my-new-feature`)
23
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,65 @@
1
+ require 'slim'
2
+ require 'opal'
3
+ require 'sprockets'
4
+
5
+ module Opal
6
+ module Slim
7
+ def self.compiled_slim source
8
+ engine = ::Slim::Engine.new
9
+ engine.call(source).gsub(/(slim_controls\w+) <</, '\1 +=')
10
+ end
11
+
12
+ def self.wrap compiled, file
13
+ <<-EOF
14
+ Template.new('#{file}') do |slim|
15
+ #{compiled}
16
+ end
17
+ EOF
18
+ end
19
+
20
+ def self.compile source, file='(slim)'
21
+ Opal.compile(wrap(compiled_slim(source), file))
22
+ end
23
+
24
+ class Processor < Tilt::Template
25
+ self.default_mime_type = 'application/javascript'
26
+
27
+ def self.engine_initialized?
28
+ true
29
+ end
30
+
31
+ def initialize_engine
32
+ require_template_library 'opal'
33
+ end
34
+
35
+ def prepare
36
+ end
37
+
38
+ def evaluate context, locals, &block
39
+ context.require_asset 'opal-slim'
40
+ Opal::Slim.compile data, context.logical_path.sub(/^templates\//, '')
41
+ end
42
+ end
43
+
44
+ class SlimProcessor < Opal::BuilderProcessors::RubyProcessor
45
+ handles :slim
46
+
47
+ def initialize *args
48
+ super
49
+ @source = prepare(@source, @filename)
50
+ end
51
+
52
+ def requires
53
+ ['opal-slim', 'erb'] + super
54
+ end
55
+
56
+ def prepare source, path
57
+ slim = ::Opal::Slim.compiled_slim(source)
58
+ ::Opal::Slim.wrap(slim, path)
59
+ end
60
+ end
61
+ end
62
+ end
63
+
64
+ Opal.append_path File.expand_path('../../../opal', __FILE__).untaint
65
+ Sprockets.register_engine '.slim', Opal::Slim::Processor
@@ -0,0 +1,5 @@
1
+ module Opal
2
+ module Slim
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'opal/slim/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "opal-slim"
8
+ spec.version = Opal::Slim::VERSION
9
+ spec.authors = ["Jamie Gaskins"]
10
+ spec.email = ["jgaskins@gmail.com"]
11
+ spec.summary = %q{Write your Opal app's templates in Slim}
12
+ spec.description = %q{Wrapper around the slim gem to let you write slim templates for your Opal app}
13
+ spec.homepage = "https://github.com/jgaskins/opal-slim"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency 'rspec', '~> 3.0'
24
+ spec.add_dependency 'slim', '~> 3.0'
25
+ spec.add_dependency 'sprockets', '>= 2.12.1', '< 4.0.0'
26
+ spec.add_dependency 'opal', '~> 0.7.0.beta1'
27
+ end
@@ -0,0 +1,49 @@
1
+ require 'template'
2
+ require 'erb'
3
+
4
+ module Temple
5
+ module Utils
6
+ def self.escape_html *args
7
+ ERB::Util.html_escape *args
8
+ end
9
+
10
+ def self.escape_html_safe *args
11
+ args.first
12
+ end
13
+ end
14
+ end
15
+
16
+ # module ERB
17
+ # module Util
18
+ # def self.html_escape_safe *args
19
+ # html_escape *args
20
+ # end
21
+ # end
22
+ # end
23
+
24
+ # class Template
25
+ # class OutputBuffer
26
+ # alias << append
27
+
28
+ # # allow tags in haml to have dynamic attributes
29
+ # def attributes(class_id, obj_ref, *attributes_hashes)
30
+ # attributes = class_id
31
+
32
+ # attributes_hashes.each do |hash|
33
+ # attributes.update hash
34
+ # end
35
+
36
+ # result = attributes.collect do |attr, value|
37
+ # if value == true
38
+ # next " #{attr}"
39
+ # elsif value == false
40
+ # next
41
+ # else
42
+ # " #{attr}='#{value}'"
43
+ # end
44
+ # end
45
+
46
+ # result.join
47
+ # end
48
+ # end
49
+ # end
@@ -0,0 +1,28 @@
1
+ require 'opal/slim'
2
+
3
+ # Don't use the nested describe, so we don't accidentally use the ::Slim module
4
+ describe Opal::Slim do
5
+ it 'compiles a plain Slim template' do
6
+ template = 'p lol'
7
+ compiled = ::Opal::Slim.compiled_slim(template)
8
+ expect(compiled).to eq %Q{_buf = []; _buf << (\"<p>lol</p>\".freeze); \n; _buf = _buf.join}
9
+ end
10
+
11
+ it 'compiles a Slim template with evaluated code' do
12
+ template = '= link_to "hi"'
13
+ compiled = ::Opal::Slim.compiled_slim(template)
14
+ expect(compiled).to eq %Q{_buf = []; _buf << (::Temple::Utils.escape_html((link_to "hi"))); \n; _buf = _buf.join}
15
+ end
16
+
17
+ it 'wraps a Slim template in a Template block' do
18
+ template = '<compiled slim>'
19
+ expected = <<-EOF
20
+ Template.new('(slim)') do |slim|
21
+ <compiled slim>
22
+ end
23
+ EOF
24
+
25
+ compiled = ::Opal::Slim.wrap(template, '(slim)')
26
+ expect(compiled).to eq expected
27
+ end
28
+ end
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: opal-slim
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jamie Gaskins
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: slim
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sprockets
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 2.12.1
76
+ - - "<"
77
+ - !ruby/object:Gem::Version
78
+ version: 4.0.0
79
+ type: :runtime
80
+ prerelease: false
81
+ version_requirements: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: 2.12.1
86
+ - - "<"
87
+ - !ruby/object:Gem::Version
88
+ version: 4.0.0
89
+ - !ruby/object:Gem::Dependency
90
+ name: opal
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: 0.7.0.beta1
96
+ type: :runtime
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: 0.7.0.beta1
103
+ description: Wrapper around the slim gem to let you write slim templates for your
104
+ Opal app
105
+ email:
106
+ - jgaskins@gmail.com
107
+ executables: []
108
+ extensions: []
109
+ extra_rdoc_files: []
110
+ files:
111
+ - ".gitignore"
112
+ - Gemfile
113
+ - LICENSE.txt
114
+ - README.md
115
+ - Rakefile
116
+ - lib/opal/slim.rb
117
+ - lib/opal/slim/version.rb
118
+ - opal-slim.gemspec
119
+ - opal/opal-slim.rb
120
+ - spec/opal/slim_spec.rb
121
+ homepage: https://github.com/jgaskins/opal-slim
122
+ licenses:
123
+ - MIT
124
+ metadata: {}
125
+ post_install_message:
126
+ rdoc_options: []
127
+ require_paths:
128
+ - lib
129
+ required_ruby_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ required_rubygems_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ requirements: []
140
+ rubyforge_project:
141
+ rubygems_version: 2.4.5
142
+ signing_key:
143
+ specification_version: 4
144
+ summary: Write your Opal app's templates in Slim
145
+ test_files:
146
+ - spec/opal/slim_spec.rb