rail 0.0.6 → 0.0.7

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: 43471296d43318f06e1781bfea739eb39bf8da7f
4
- data.tar.gz: be098116b23160188c2696295bc7758d8876f1d7
3
+ metadata.gz: 0a66f7d5b9a7e1436ce075bcf244d8c020b14b29
4
+ data.tar.gz: 0bff180762f3b1be3d8193e8a36cb810ebc39980
5
5
  SHA512:
6
- metadata.gz: 4f0f8b61cfef6396c5a1cc20cf14b04413eff13161ea2bc347b7131cc2ad036432ce5dab6162e93e48cf87b9721af39b7ecee7147810c00b4b2eacdc97bb84c7
7
- data.tar.gz: 8143e93f3ec6e07273f04d0ac0854977a67a72373f70bdaa4c2659895b6a3cee2bb933b18079dda6c242855a30e570b11ad6b508df896bafcfe82be61883c323
6
+ metadata.gz: 8779ed872c394c8df542f8d15277b235e7c1de0936ead82e8b1c6e6fb129b312d6789ae7f5dd8f3a0d83d7d41de8b2f20d21c12a4d939fee8033559ebcb3dc4a
7
+ data.tar.gz: facff4a130a3574032a7b1e5fdd52c5210dff76929260dcd6ad7df54a12f0208d463fbce56cce13525e09960e664c5e9e03ea5a6bfba2b3877f1f9512f9cce51
data/CHANGELOG.md CHANGED
@@ -1,4 +1,8 @@
1
- ## Rail (develop)
1
+ ## Rail 0.0.7 (July 15, 2014)
2
+
3
+ * Added a CLI for generating project directories.
4
+
5
+ ## Rail 0.0.6 (July 13, 2014)
2
6
 
3
7
  * Dropped the dependency on Sprockets.
4
8
  * Implemented the rendering of templates inside layouts.
data/README.md CHANGED
@@ -8,28 +8,62 @@ assets, and it includes the following components:
8
8
  * [Haml](http://haml.info/) for HTML, and
9
9
  * [Sass](http://sass-lang.com/) for CSS.
10
10
 
11
- ## Installation
11
+ ## Straightforward Installation
12
12
 
13
- First of all, include the gem in your `Gemfile`. Here is an example:
13
+ Install the gem:
14
+
15
+ ```bash
16
+ $ gem install rail
17
+ ```
18
+
19
+ Create a new project:
20
+
21
+ ```bash
22
+ $ rail new my_project
23
+ ```
24
+
25
+ Run [Bundler](http://bundler.io/):
26
+
27
+ ```bash
28
+ $ cd ./my_project
29
+ $ bundle
30
+ ```
31
+
32
+ Run the server:
33
+
34
+ ```bash
35
+ $ rake server
36
+ ```
37
+
38
+ Open `http://localhost:3000` in your browser, see “My Project,” and enjoy.
39
+
40
+ Under the hood, the `rail new my_project` command creates a new folder in the
41
+ current directory called `my_project` and initializes a basic Rail project
42
+ inside that folder. In this case, `MyProject` is used as the class name of
43
+ the project. Feel free to replace `my_project` with the name of your project.
44
+
45
+ ## Manual Installation
46
+
47
+ Include the gem in your `Gemfile`:
14
48
 
15
49
  ```ruby
16
50
  source 'https://rubygems.org'
17
51
 
18
- gem 'rail', '~> 0.0.6'
52
+ gem 'rail', '~> 0.0.7'
19
53
 
20
54
  # The rest is optional
21
55
  gem 'redcarpet', '~> 3.1.2' # your favorit complement to Haml
22
56
  gem 'thin', '~> 1.6.2' # your favorit Web server
23
57
  ```
24
58
 
25
- Then run [Bundler](http://bundler.io/):
59
+ Run [Bundler](http://bundler.io/):
26
60
 
27
61
  ```bash
28
62
  $ bundle
29
63
  ```
30
64
 
31
- Now we need to create three files: `config/application.rb`, `config.ru`, and
32
- `Rakefile`. In `config/application.rb`:
65
+ Create three files: `config/application.rb`, `config.ru`, and `Rakefile`.
66
+ In `config/application.rb`:
33
67
 
34
68
  ```ruby
35
69
  require 'bundler'
@@ -57,7 +91,7 @@ require_relative 'config/application'
57
91
  MyProject::Application.load_tasks
58
92
  ```
59
93
 
60
- Feel free to replace `MyProject` with the name of your project. That’s it.
94
+ Feel free to replace `MyProject` with the name of your project.
61
95
 
62
96
  ## Usage
63
97
 
data/bin/rail ADDED
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
4
+
5
+ require 'rail/generator'
6
+
7
+ unless ARGV.length == 2 && ARGV[0] == 'new'
8
+ puts 'Usage: rail new <project_name>'
9
+ exit 1
10
+ end
11
+
12
+ begin
13
+ Rail::Generator.new(root_dir: ARGV[1]).run
14
+ rescue Rail::Generator::Error => e
15
+ puts e
16
+ exit 1
17
+ end
18
+
19
+ # vim: set ft=ruby
data/lib/generator.rb ADDED
@@ -0,0 +1,73 @@
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
@@ -0,0 +1,47 @@
1
+ require 'generator'
2
+
3
+ module Rail
4
+ class Generator < ::Generator
5
+ Error = Class.new(StandardError)
6
+
7
+ FILES = [
8
+ 'app/assets/javascripts/application.js.coffee',
9
+ 'app/assets/stylesheets/application.css.scss',
10
+ 'app/helpers/application_helper.rb',
11
+ 'app/views/layouts/application.html.haml.erb',
12
+ 'config/application.rb.erb',
13
+ 'config.ru.erb',
14
+ 'Gemfile',
15
+ 'public/favicon.png',
16
+ 'Rakefile.erb'
17
+ ]
18
+
19
+ def initialize(options)
20
+ root_dir = options.fetch(:root_dir)
21
+ template_dir = File.expand_path('../templates', __FILE__)
22
+
23
+ project_name = (root_dir.split('/').last || '')
24
+ .gsub(/^[^a-zA-Z]*/, '')
25
+ .gsub(/[^\w]/, '')
26
+ .gsub(/^\w|_\w/, &:upcase)
27
+ .gsub(/_+/, ' ')
28
+
29
+ class_name = project_name.gsub(' ', '')
30
+
31
+ @locals = { class_name: class_name, project_name: project_name }
32
+
33
+ raise Error, 'The project name is invalid.' if class_name.empty?
34
+
35
+ super(root_dir: root_dir, template_dir: template_dir)
36
+ end
37
+
38
+ def run
39
+ raise Error, 'The directory already exists.' if File.directory?(root_dir)
40
+ super(FILES, @locals)
41
+ end
42
+
43
+ def report(message)
44
+ puts "Creating '#{ message }'..."
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rail'
@@ -0,0 +1,3 @@
1
+ require_relative 'config/application'
2
+
3
+ <%= class_name %>::Application.load_tasks
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,10 @@
1
+ !!! 5
2
+ %html
3
+ %head
4
+ %meta{ charset: 'utf-8' }
5
+ %title <%= project_name %>
6
+ %link{ href: '/application.css', rel: 'stylesheet', media: 'all' }
7
+ %link{ href: '/favicon.png', rel: 'shortcut icon', type: 'image/png' }
8
+ %body
9
+ %h1 <%= project_name %>
10
+ %script{ src: '/application.js', type: 'text/javascript' }
@@ -0,0 +1,17 @@
1
+ require 'bundler'
2
+ Bundler.require(:default)
3
+
4
+ module <%= class_name %>
5
+ class Application < Rail::Application
6
+ # Import assets from other gems:
7
+ # config.gems << 'turbolinks'
8
+ #
9
+ # Precompile assets using `rake assets`:
10
+ # config.precompile << 'application.css'
11
+ # config.precompile << 'application.js'
12
+ # config.precompile << 'index.html'
13
+ #
14
+ # Compress assets:
15
+ # config.compress = true
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ require_relative 'config/application'
2
+
3
+ run <%= class_name %>::Application.new
File without changes
data/lib/rail/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rail
2
- VERSION = '0.0.6'
2
+ VERSION = '0.0.7'
3
3
  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.6
4
+ version: 0.0.7
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-13 00:00:00.000000000 Z
11
+ date: 2014-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -112,7 +112,8 @@ description: A light framework for front-end development closely following the c
112
112
  of Ruby on Rails.
113
113
  email:
114
114
  - ivan.ukhov@gmail.com
115
- executables: []
115
+ executables:
116
+ - rail
116
117
  extensions: []
117
118
  extra_rdoc_files: []
118
119
  files:
@@ -124,10 +125,13 @@ files:
124
125
  - LICENSE.txt
125
126
  - README.md
126
127
  - Rakefile
128
+ - bin/rail
129
+ - lib/generator.rb
127
130
  - lib/rail.rb
128
131
  - lib/rail/application.rb
129
132
  - lib/rail/browser.rb
130
133
  - lib/rail/context.rb
134
+ - lib/rail/generator.rb
131
135
  - lib/rail/pipeline.rb
132
136
  - lib/rail/processor.rb
133
137
  - lib/rail/processor/base.rb
@@ -139,6 +143,15 @@ files:
139
143
  - lib/rail/support.rb
140
144
  - lib/rail/tasks/assets.rake
141
145
  - lib/rail/tasks/server.rake
146
+ - lib/rail/templates/Gemfile
147
+ - lib/rail/templates/Rakefile.erb
148
+ - lib/rail/templates/app/assets/javascripts/application.js.coffee
149
+ - lib/rail/templates/app/assets/stylesheets/application.css.scss
150
+ - lib/rail/templates/app/helpers/application_helper.rb
151
+ - lib/rail/templates/app/views/layouts/application.html.haml.erb
152
+ - lib/rail/templates/config.ru.erb
153
+ - lib/rail/templates/config/application.rb.erb
154
+ - lib/rail/templates/public/favicon.png
142
155
  - lib/rail/version.rb
143
156
  - rail.gemspec
144
157
  - spec/coffee_spec.rb