rail 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -0
  3. data/Guardfile +10 -0
  4. data/README.md +10 -12
  5. data/Rakefile +4 -7
  6. data/bin/rail +1 -1
  7. data/lib/rail.rb +7 -21
  8. data/lib/rail/application.rb +10 -82
  9. data/lib/rail/browser.rb +6 -10
  10. data/lib/rail/generator.rb +13 -20
  11. data/lib/rail/pipeline.rb +13 -13
  12. data/lib/rail/precompiler.rb +58 -0
  13. data/lib/rail/processor/base.rb +1 -1
  14. data/lib/rail/processor/coffee_script.rb +1 -1
  15. data/lib/rail/processor/haml.rb +2 -2
  16. data/lib/rail/request.rb +12 -2
  17. data/lib/rail/tasks/assets.rake +1 -1
  18. data/lib/rail/version.rb +1 -1
  19. data/lib/support/generator.rb +76 -0
  20. data/lib/support/inflector.rb +16 -0
  21. data/lib/support/loader.rb +55 -0
  22. data/lib/support/query_string.rb +8 -0
  23. data/lib/support/query_struct.rb +10 -0
  24. data/rail.gemspec +5 -0
  25. data/spec/{coffee_spec.rb → features/coffee_spec.rb} +5 -7
  26. data/spec/{haml_spec.rb → features/haml_spec.rb} +6 -8
  27. data/spec/{sass_spec.rb → features/sass_spec.rb} +5 -7
  28. data/spec/{project → fixtures/project}/app/assets/javascripts/application.js.coffee +0 -0
  29. data/spec/{project → fixtures/project}/app/assets/javascripts/font.coffee +0 -0
  30. data/spec/{project → fixtures/project}/app/assets/javascripts/parser.js.coffee +0 -0
  31. data/spec/{project → fixtures/project}/app/assets/stylesheets/_reset.scss +0 -0
  32. data/spec/{project → fixtures/project}/app/assets/stylesheets/application.css.scss +0 -0
  33. data/spec/{project → fixtures/project}/app/helpers/application_helper.rb +0 -0
  34. data/spec/{project → fixtures/project}/app/views/articles/about.html.haml +0 -0
  35. data/spec/{project → fixtures/project}/app/views/layouts/application.html.haml +0 -0
  36. data/spec/{project → fixtures/project}/app/views/layouts/articles.html.haml +0 -0
  37. data/spec/{project → fixtures/project}/config/application.rb +0 -0
  38. data/spec/{project → fixtures/project}/controller.rb +0 -0
  39. data/spec/lib/rail/application_spec.rb +38 -0
  40. data/spec/lib/rail/generator_spec.rb +14 -0
  41. data/spec/lib/rail/precompiler_spec.rb +25 -0
  42. data/spec/lib/rail/request_spec.rb +16 -0
  43. data/spec/lib/support/inflector_spec.rb +18 -0
  44. data/spec/lib/support/loader_spec.rb +61 -0
  45. data/spec/lib/support/query_string_spec.rb +11 -0
  46. data/spec/lib/support/query_struct_spec.rb +28 -0
  47. data/spec/spec_helper.rb +6 -0
  48. data/spec/support/common_helper.rb +5 -0
  49. metadata +99 -32
  50. data/lib/generator.rb +0 -73
  51. data/lib/rail/support.rb +0 -7
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+ require 'rail/request'
3
+
4
+ RSpec.describe Rail::Request do
5
+ describe '#path' do
6
+ it 'appends .html when no extension is given' do
7
+ env = { 'PATH_INFO' => '/foo/bar' }
8
+ expect(described_class.new(env).path).to eq '/foo/bar.html'
9
+ end
10
+
11
+ it 'substitutes /index.html for /' do
12
+ env = { 'PATH_INFO' => '/' }
13
+ expect(described_class.new(env).path).to eq '/index.html'
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+ require 'support/inflector'
3
+
4
+ RSpec.describe Support::Inflector do
5
+ describe '.titelize' do
6
+ it 'returns pretty strings' do
7
+ { " \t pro ject \n" => 'Pro Ject',
8
+ '42_my project' => 'My Project',
9
+ 'project42' => 'Project42',
10
+ 'project 42' => 'Project 42',
11
+ 'project___ 42nd' => 'Project 42nd',
12
+ 'PRO ject' => 'PRO Ject'
13
+ }.each_pair do |input, output|
14
+ expect(described_class.titelize(input)).to eq output
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+ require 'support/loader'
3
+
4
+ RSpec.describe Support::Loader do
5
+ before do
6
+ if Object.const_defined?(:ApplicationHelper)
7
+ Object.send(:remove_const, :ApplicationHelper)
8
+ end
9
+ end
10
+
11
+ subject { described_class.new(pattern) }
12
+
13
+ describe '#find' do
14
+ context 'there are files to process' do
15
+ let(:pattern) { File.join(fixture_path, 'project/app/helpers/*.rb') }
16
+
17
+ it 'loads and returns modules' do
18
+ expect(Object.const_defined?(:ApplicationHelper)).to be false
19
+
20
+ result = subject.find
21
+
22
+ expect(Object.const_defined?(:ApplicationHelper)).to be true
23
+ expect(result).to eq [ApplicationHelper]
24
+ end
25
+
26
+ it 'does not reload modules if they have not unchanged' do
27
+ expect(subject.reload?).to be true
28
+
29
+ subject.find
30
+
31
+ expect(subject.reload?).to be false
32
+ end
33
+
34
+ it 'reloads modules if they have changed' do
35
+ expect(subject.reload?).to be true
36
+
37
+ subject.find
38
+
39
+ expect(File).to receive(:mtime).and_return(Time.now)
40
+ expect(subject.reload?).to be true
41
+ end
42
+ end
43
+
44
+ context 'there are no files to process' do
45
+ let(:pattern) { File.join(fixture_path, 'project/app/helpers/*.br') }
46
+
47
+ it 'returns an empty array' do
48
+ expect(subject.find).to be_empty
49
+ end
50
+
51
+ it 'does not load/reload anything' do
52
+ expect(subject.reload?).to be true
53
+
54
+ subject.find
55
+
56
+ allow(File).to receive(:mtime).and_return(Time.now)
57
+ expect(subject.reload?).to be false
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+ require 'support/query_string'
3
+
4
+ RSpec.describe Support::QueryString do
5
+ subject { described_class.new('hello') }
6
+
7
+ it 'permits querying' do
8
+ expect(subject.hello?).to be true
9
+ expect(subject.goodbye?).to be false
10
+ end
11
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+ require 'support/query_struct'
3
+
4
+ RSpec.describe Support::QueryStruct do
5
+ subject { described_class.new(first: 1, second: 2) }
6
+
7
+ describe '#new' do
8
+ it 'assigns attributes according to the given options' do
9
+ expect(subject.first).to eq 1
10
+ expect(subject.second).to eq 2
11
+ end
12
+ end
13
+
14
+ it 'permits reading arbitrary attributes' do
15
+ expect(subject.fourty_second).to be nil
16
+ end
17
+
18
+ it 'permits writing arbitrary attributes' do
19
+ subject.fourty_second = 42
20
+ expect(subject.fourty_second).to eq 42
21
+ end
22
+
23
+ it 'permits querying arbitrary attributes' do
24
+ expect(subject.fourty_second?).to be false
25
+ subject.fourty_second = 42
26
+ expect(subject.fourty_second?).to be true
27
+ end
28
+ end
@@ -0,0 +1,6 @@
1
+ require 'support/common_helper'
2
+
3
+ RSpec.configure do |config|
4
+ config.include CommonHelper
5
+ config.disable_monkey_patching!
6
+ end
@@ -0,0 +1,5 @@
1
+ module CommonHelper
2
+ def fixture_path
3
+ File.expand_path('../../fixtures', __FILE__)
4
+ end
5
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rail
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Ukhov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-15 00:00:00.000000000 Z
11
+ date: 2014-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -108,6 +108,48 @@ dependencies:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: '1.6'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '3.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '3.0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: guard
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '2.6'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '2.6'
139
+ - !ruby/object:Gem::Dependency
140
+ name: guard-rspec
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '4.3'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '4.3'
111
153
  description: A light framework for front-end development closely following the conventions
112
154
  of Ruby on Rails.
113
155
  email:
@@ -122,17 +164,18 @@ files:
122
164
  - ".yardopts"
123
165
  - CHANGELOG.md
124
166
  - Gemfile
167
+ - Guardfile
125
168
  - LICENSE.txt
126
169
  - README.md
127
170
  - Rakefile
128
171
  - bin/rail
129
- - lib/generator.rb
130
172
  - lib/rail.rb
131
173
  - lib/rail/application.rb
132
174
  - lib/rail/browser.rb
133
175
  - lib/rail/context.rb
134
176
  - lib/rail/generator.rb
135
177
  - lib/rail/pipeline.rb
178
+ - lib/rail/precompiler.rb
136
179
  - lib/rail/processor.rb
137
180
  - lib/rail/processor/base.rb
138
181
  - lib/rail/processor/coffee_script.rb
@@ -140,7 +183,6 @@ files:
140
183
  - lib/rail/processor/sass.rb
141
184
  - lib/rail/request.rb
142
185
  - lib/rail/server.rb
143
- - lib/rail/support.rb
144
186
  - lib/rail/tasks/assets.rake
145
187
  - lib/rail/tasks/server.rake
146
188
  - lib/rail/templates/Gemfile
@@ -153,21 +195,36 @@ files:
153
195
  - lib/rail/templates/config/application.rb.erb
154
196
  - lib/rail/templates/public/favicon.png
155
197
  - lib/rail/version.rb
198
+ - lib/support/generator.rb
199
+ - lib/support/inflector.rb
200
+ - lib/support/loader.rb
201
+ - lib/support/query_string.rb
202
+ - lib/support/query_struct.rb
156
203
  - rail.gemspec
157
- - spec/coffee_spec.rb
158
- - spec/haml_spec.rb
159
- - spec/project/app/assets/javascripts/application.js.coffee
160
- - spec/project/app/assets/javascripts/font.coffee
161
- - spec/project/app/assets/javascripts/parser.js.coffee
162
- - spec/project/app/assets/stylesheets/_reset.scss
163
- - spec/project/app/assets/stylesheets/application.css.scss
164
- - spec/project/app/helpers/application_helper.rb
165
- - spec/project/app/views/articles/about.html.haml
166
- - spec/project/app/views/layouts/application.html.haml
167
- - spec/project/app/views/layouts/articles.html.haml
168
- - spec/project/config/application.rb
169
- - spec/project/controller.rb
170
- - spec/sass_spec.rb
204
+ - spec/features/coffee_spec.rb
205
+ - spec/features/haml_spec.rb
206
+ - spec/features/sass_spec.rb
207
+ - spec/fixtures/project/app/assets/javascripts/application.js.coffee
208
+ - spec/fixtures/project/app/assets/javascripts/font.coffee
209
+ - spec/fixtures/project/app/assets/javascripts/parser.js.coffee
210
+ - spec/fixtures/project/app/assets/stylesheets/_reset.scss
211
+ - spec/fixtures/project/app/assets/stylesheets/application.css.scss
212
+ - spec/fixtures/project/app/helpers/application_helper.rb
213
+ - spec/fixtures/project/app/views/articles/about.html.haml
214
+ - spec/fixtures/project/app/views/layouts/application.html.haml
215
+ - spec/fixtures/project/app/views/layouts/articles.html.haml
216
+ - spec/fixtures/project/config/application.rb
217
+ - spec/fixtures/project/controller.rb
218
+ - spec/lib/rail/application_spec.rb
219
+ - spec/lib/rail/generator_spec.rb
220
+ - spec/lib/rail/precompiler_spec.rb
221
+ - spec/lib/rail/request_spec.rb
222
+ - spec/lib/support/inflector_spec.rb
223
+ - spec/lib/support/loader_spec.rb
224
+ - spec/lib/support/query_string_spec.rb
225
+ - spec/lib/support/query_struct_spec.rb
226
+ - spec/spec_helper.rb
227
+ - spec/support/common_helper.rb
171
228
  homepage: https://github.com/IvanUkhov/rail
172
229
  licenses:
173
230
  - MIT
@@ -193,18 +250,28 @@ signing_key:
193
250
  specification_version: 4
194
251
  summary: A light framework for front-end development inspired by Rails
195
252
  test_files:
196
- - spec/coffee_spec.rb
197
- - spec/haml_spec.rb
198
- - spec/project/app/assets/javascripts/application.js.coffee
199
- - spec/project/app/assets/javascripts/font.coffee
200
- - spec/project/app/assets/javascripts/parser.js.coffee
201
- - spec/project/app/assets/stylesheets/_reset.scss
202
- - spec/project/app/assets/stylesheets/application.css.scss
203
- - spec/project/app/helpers/application_helper.rb
204
- - spec/project/app/views/articles/about.html.haml
205
- - spec/project/app/views/layouts/application.html.haml
206
- - spec/project/app/views/layouts/articles.html.haml
207
- - spec/project/config/application.rb
208
- - spec/project/controller.rb
209
- - spec/sass_spec.rb
253
+ - spec/features/coffee_spec.rb
254
+ - spec/features/haml_spec.rb
255
+ - spec/features/sass_spec.rb
256
+ - spec/fixtures/project/app/assets/javascripts/application.js.coffee
257
+ - spec/fixtures/project/app/assets/javascripts/font.coffee
258
+ - spec/fixtures/project/app/assets/javascripts/parser.js.coffee
259
+ - spec/fixtures/project/app/assets/stylesheets/_reset.scss
260
+ - spec/fixtures/project/app/assets/stylesheets/application.css.scss
261
+ - spec/fixtures/project/app/helpers/application_helper.rb
262
+ - spec/fixtures/project/app/views/articles/about.html.haml
263
+ - spec/fixtures/project/app/views/layouts/application.html.haml
264
+ - spec/fixtures/project/app/views/layouts/articles.html.haml
265
+ - spec/fixtures/project/config/application.rb
266
+ - spec/fixtures/project/controller.rb
267
+ - spec/lib/rail/application_spec.rb
268
+ - spec/lib/rail/generator_spec.rb
269
+ - spec/lib/rail/precompiler_spec.rb
270
+ - spec/lib/rail/request_spec.rb
271
+ - spec/lib/support/inflector_spec.rb
272
+ - spec/lib/support/loader_spec.rb
273
+ - spec/lib/support/query_string_spec.rb
274
+ - spec/lib/support/query_struct_spec.rb
275
+ - spec/spec_helper.rb
276
+ - spec/support/common_helper.rb
210
277
  has_rdoc:
data/lib/generator.rb DELETED
@@ -1,73 +0,0 @@
1
- require 'erb'
2
- require 'ostruct'
3
- require 'fileutils'
4
-
5
- class Generator
6
- attr_reader :root_dir, :template_dir
7
-
8
- def initialize(options)
9
- @root_dir = options.fetch(:root_dir)
10
- @template_dir = options.fetch(:template_dir)
11
- end
12
-
13
- def run(files, locals = {})
14
- context = OpenStruct.new(locals)
15
- files.each { |file| process(file, context) }
16
- end
17
-
18
- private
19
-
20
- def process(file, context)
21
- source = find(file)
22
- destination = route(file)
23
-
24
- directory = File.dirname(destination)
25
- unless File.directory?(directory)
26
- report(directory)
27
- make(directory)
28
- end
29
-
30
- report(destination)
31
- if template?(file)
32
- dump(transform(load(source), context), destination)
33
- else
34
- copy(source, destination)
35
- end
36
- end
37
-
38
- def template?(file)
39
- File.extname(file) == '.erb'
40
- end
41
-
42
- def find(file)
43
- File.join(template_dir, file)
44
- end
45
-
46
- def route(file)
47
- File.join(root_dir, file).gsub(/\.erb$/, '')
48
- end
49
-
50
- def report(message)
51
- end
52
-
53
- def make(destination)
54
- FileUtils.mkdir_p(destination)
55
- end
56
-
57
- def copy(source, destination)
58
- FileUtils.cp(source, destination)
59
- end
60
-
61
- def load(source)
62
- File.read(source)
63
- end
64
-
65
- def dump(content, destination)
66
- File.open(destination, 'w') { |file| file.write(content) }
67
- end
68
-
69
- def transform(content, context)
70
- context.singleton_class.class_eval('def get_binding; binding; end')
71
- ERB.new(content).result(context.get_binding)
72
- end
73
- end
data/lib/rail/support.rb DELETED
@@ -1,7 +0,0 @@
1
- module Rail
2
- module Support
3
- def self.constantize(name)
4
- const_get(name.split(/[\s_]+/).map(&:capitalize).join)
5
- end
6
- end
7
- end