bob-compiler 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,76 @@
1
+ require 'test_helper'
2
+ require 'nokogiri'
3
+
4
+ require 'bob/compiler/layout'
5
+
6
+ class LayoutsTest < Minitest::Test
7
+ include FixtureHelpers
8
+
9
+ self.fixture_path << '/layout'
10
+
11
+ fixtures.each do |name|
12
+ test "Fixture #{name}" do
13
+ input = fixture "#{name}.html"
14
+ expected = fixture "#{name}.js"
15
+
16
+ assert_equal expected, compile(input)
17
+ assert_predicate @compiled, :valid?
18
+ end
19
+ end
20
+
21
+ test "Container node" do
22
+ compile <<-HTML
23
+ <html>
24
+ <body>
25
+ <div>Not container</div>
26
+ <div bob-container>Container node</div>
27
+ <div>Also not container</div>
28
+ </body>
29
+ </html>
30
+ HTML
31
+
32
+ assert_equal "Container node", @compiled.container.text
33
+ assert_predicate @compiled, :valid?
34
+ end
35
+
36
+ test "Missing container" do
37
+ compile <<-HTML
38
+ <html>
39
+ <body>
40
+ <div>Not container</div>
41
+ <div>Also not container</div>
42
+ </body>
43
+ </html>
44
+ HTML
45
+
46
+ refute_predicate @compiled, :valid?
47
+ refute_predicate @compiled, :well_formed?
48
+ refute_predicate @compiled, :warnings?
49
+ assert_predicate @compiled, :errors?
50
+ end
51
+
52
+ test "Multiple containers" do
53
+ compile <<-HTML
54
+ <html>
55
+ <body>
56
+ <div>Not container</div>
57
+ <div bob-container>Container 1</div>
58
+ <div bob-container>Container 2</div>
59
+ <div bob-container>Container 3</div>
60
+ </body>
61
+ </html>
62
+ HTML
63
+
64
+ assert_predicate @compiled, :valid?
65
+ refute_predicate @compiled, :well_formed?
66
+ assert_predicate @compiled, :warnings?
67
+ refute_predicate @compiled, :errors?
68
+ end
69
+
70
+ private
71
+ def compile(str)
72
+ doc = Nokogiri::HTML(str)
73
+ @compiled = Bob::Compiler::Layout.new(doc.root)
74
+ @compiled.result
75
+ end
76
+ end
@@ -0,0 +1,51 @@
1
+ require 'test_helper'
2
+ require 'nokogiri'
3
+
4
+ require 'bob/compiler/template'
5
+
6
+ class TemplatesTest < Minitest::Test
7
+ include FixtureHelpers
8
+
9
+ self.fixture_path << '/templates'
10
+
11
+ fixtures.each do |name|
12
+ test "Fixture #{name}" do
13
+ input = fixture "#{name}.html"
14
+ expected = fixture "#{name}.js"
15
+
16
+ assert_equal expected, compile(name, input)
17
+ assert_predicate @compiled, :valid?
18
+ end
19
+ end
20
+
21
+ test "Blank document" do
22
+ compile "blank-document", ""
23
+
24
+ refute_predicate @compiled, :valid?
25
+ refute_predicate @compiled, :well_formed?
26
+ refute_predicate @compiled, :warnings?
27
+ assert_predicate @compiled, :errors?
28
+ end
29
+
30
+ test "Missing container" do
31
+ compile "missing-container", <<-HTML
32
+ <html>
33
+ <body>
34
+ <div>Not container</div>
35
+ <div>Also not container</div>
36
+ </body>
37
+ </html>
38
+ HTML
39
+
40
+ refute_predicate @compiled, :valid?
41
+ refute_predicate @compiled, :well_formed?
42
+ refute_predicate @compiled, :warnings?
43
+ assert_predicate @compiled, :errors?
44
+ end
45
+
46
+ private
47
+ def compile(name, str)
48
+ @compiled = Bob::Compiler::Template.new(name, str)
49
+ @compiled.result
50
+ end
51
+ end
@@ -0,0 +1,43 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/pride'
3
+
4
+ require 'active_support'
5
+ require 'active_support/concern'
6
+ require 'active_support/core_ext/class/attribute'
7
+ require 'active_support/testing/declarative'
8
+
9
+ # Get rid of the annoying warning
10
+ I18n.enforce_available_locales = true
11
+
12
+ class Minitest::Test
13
+ extend ActiveSupport::Testing::Declarative
14
+ end
15
+
16
+ module FixtureHelpers
17
+ extend ActiveSupport::Concern
18
+
19
+ included do
20
+ class_attribute :fixture_path
21
+ class_attribute :fixture_cache
22
+
23
+ self.fixture_path = File.expand_path('../fixtures', __FILE__)
24
+ self.fixture_cache = {}
25
+ end
26
+
27
+ module ClassMethods
28
+ def fixture(filename)
29
+ fixture_cache[filename] ||= File.read(File.join(fixture_path, filename))
30
+ end
31
+
32
+ def fixtures
33
+ Dir.glob(File.join(fixture_path, '*.js')).map do |filename|
34
+ File.basename(filename).gsub(/\.js\z/, '')
35
+ end
36
+ end
37
+ end
38
+
39
+ private
40
+ def fixture(filename)
41
+ self.class.fixture(filename)
42
+ end
43
+ end
metadata ADDED
@@ -0,0 +1,180 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bob-compiler
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Godfrey Chan
8
+ - Gabe Scholz
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-01-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: nokogiri
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: 1.6.4
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: 1.6.4
28
+ - !ruby/object:Gem::Dependency
29
+ name: activesupport
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: 3.2.0
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: 3.2.0
42
+ - !ruby/object:Gem::Dependency
43
+ name: bundler
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '1.7'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '1.7'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rake
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '10.0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '10.0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: minitest
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: 5.4.0
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: 5.4.0
84
+ - !ruby/object:Gem::Dependency
85
+ name: pry
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: 0.10.1
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: 0.10.1
98
+ description:
99
+ email:
100
+ - godfreykfc@gmail.com
101
+ - gabe@brewhouse.io
102
+ executables: []
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - ".gitignore"
107
+ - Gemfile
108
+ - Gemfile.lock
109
+ - LICENSE
110
+ - README.md
111
+ - Rakefile
112
+ - bob-compiler.gemspec
113
+ - lib/bob/compiler.rb
114
+ - lib/bob/compiler/base.rb
115
+ - lib/bob/compiler/block.rb
116
+ - lib/bob/compiler/buffer.rb
117
+ - lib/bob/compiler/editable.rb
118
+ - lib/bob/compiler/layout.rb
119
+ - lib/bob/compiler/message.rb
120
+ - lib/bob/compiler/substitution.rb
121
+ - lib/bob/compiler/template.rb
122
+ - lib/bob/compiler/version.rb
123
+ - lib/bob/compiler/walker.rb
124
+ - test/blocks_test.rb
125
+ - test/fixtures/blocks/bar.html
126
+ - test/fixtures/blocks/bar.js
127
+ - test/fixtures/blocks/foo.html
128
+ - test/fixtures/blocks/foo.js
129
+ - test/fixtures/blocks/foobar.html
130
+ - test/fixtures/blocks/foobar.js
131
+ - test/fixtures/blocks/substitions.html
132
+ - test/fixtures/blocks/substitions.js
133
+ - test/fixtures/layout/simple.html
134
+ - test/fixtures/layout/simple.js
135
+ - test/fixtures/templates/simple.html
136
+ - test/fixtures/templates/simple.js
137
+ - test/layouts_test.rb
138
+ - test/templates_test.rb
139
+ - test/test_helper.rb
140
+ homepage: https://github.com/BrewhouseTeam/bob-compiler
141
+ licenses:
142
+ - MIT
143
+ metadata: {}
144
+ post_install_message:
145
+ rdoc_options: []
146
+ require_paths:
147
+ - lib
148
+ required_ruby_version: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ required_rubygems_version: !ruby/object:Gem::Requirement
154
+ requirements:
155
+ - - ">="
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ requirements: []
159
+ rubyforge_project:
160
+ rubygems_version: 2.4.5
161
+ signing_key:
162
+ specification_version: 4
163
+ summary: A compiler for Bob templates
164
+ test_files:
165
+ - test/blocks_test.rb
166
+ - test/fixtures/blocks/bar.html
167
+ - test/fixtures/blocks/bar.js
168
+ - test/fixtures/blocks/foo.html
169
+ - test/fixtures/blocks/foo.js
170
+ - test/fixtures/blocks/foobar.html
171
+ - test/fixtures/blocks/foobar.js
172
+ - test/fixtures/blocks/substitions.html
173
+ - test/fixtures/blocks/substitions.js
174
+ - test/fixtures/layout/simple.html
175
+ - test/fixtures/layout/simple.js
176
+ - test/fixtures/templates/simple.html
177
+ - test/fixtures/templates/simple.js
178
+ - test/layouts_test.rb
179
+ - test/templates_test.rb
180
+ - test/test_helper.rb