create 0.1.1 → 0.1.2

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.
Files changed (4) hide show
  1. data/README.textile +36 -0
  2. data/create.gemspec +2 -2
  3. data/lib/create.rb +71 -23
  4. metadata +2 -1
data/README.textile ADDED
@@ -0,0 +1,36 @@
1
+ h1. Create
2
+
3
+ A command line utility, which based on supplied arguments creates a handy directory structure and files. Basically it fires up several @File.open@ and does all the code generation routine for you.
4
+
5
+ The first argument is your app's name, it is required.
6
+
7
+ List of currently available arguments: @haml erb sass scss reset jquery prototype datamapper textile markdown git@.
8
+
9
+ h3. Install
10
+
11
+ <pre>
12
+ gem install create
13
+ </pre>
14
+
15
+ h3. Example
16
+
17
+ *Input:*
18
+
19
+ <pre>
20
+ create myapp haml sass reset jquery datamapper
21
+ </pre>
22
+
23
+ *Output:*
24
+
25
+ <pre>
26
+ new myapp.rb
27
+ new config.ru
28
+ new Gemfile
29
+ new views/layout.haml
30
+ new views/index.haml
31
+ new public/stylesheets/reset.css
32
+ new public/javascripts/application.js
33
+ new public/javascripts/jquery.min.js
34
+ </pre>
35
+
36
+ _What a timesaver!_
data/create.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = 'create'
3
- gem.version = '0.1.1'
3
+ gem.version = '0.1.2'
4
4
  gem.date = '2011-07-05'
5
5
 
6
6
  gem.description = 'Sinatra directory structure and code generator.'
@@ -9,7 +9,7 @@ Gem::Specification.new do |gem|
9
9
  gem.author = 'Denis Fadeev'
10
10
  gem.email = 'denis@fadeev.in'
11
11
 
12
- gem.files = %w{ create.gemspec lib/create.rb bin/create }
12
+ gem.files = %w{ README.textile create.gemspec lib/create.rb bin/create }
13
13
 
14
14
  gem.executable = 'create'
15
15
 
data/lib/create.rb CHANGED
@@ -3,19 +3,41 @@ require 'open-uri'
3
3
 
4
4
  include FileUtils
5
5
 
6
- arguments = %w{ haml erb sass reset jquery prototype datamapper textile }
6
+ def say state, message
7
+ puts " \033[32mnew\033[0m\ " + message if state == 'new'
8
+ puts " \033[31merror\033[0m\ " + message if state == 'error'
9
+ end
10
+
11
+ arguments = %w{ haml erb sass scss reset jquery prototype datamapper textile markdown git }
7
12
  arguments.each do |argument|
8
13
  instance_variable_set("@#{argument}", true) if ARGV.include? argument
9
14
  end
10
15
 
11
16
  if ARGV.empty?
12
- puts " \033[31merror\033[0m\ Please supply at least one argument (name of the app)."
13
- exit
17
+ puts <<-TEXT
18
+ Create generates a template for Sinatra app.
19
+
20
+ Input:
21
+ create myapp [options]
22
+
23
+ Output:
24
+ new myapp.rb
25
+ new config.ru
26
+ new Gemfile
27
+ new public/stylesheets/application.css
28
+ new public/scripts/application.js
29
+
30
+ For a list of options type the following: create --options
31
+ TEXT
32
+ exit
33
+ elsif ARGV.first == '--options'
34
+ puts ' Options: ' + arguments.join(' ')
35
+ exit
14
36
  elsif arguments.include?(ARGV.first)
15
- puts " \033[31merror\033[0m\ First argument cannot be #{arguments}."
37
+ say 'error', "First argument cannot match any of the following options: #{arguments}."
16
38
  exit
17
39
  elsif Dir.exists?(ARGV.first)
18
- puts " \033[31merror\033[0m\ Directory '#{ARGV.first}' already exists."
40
+ say 'error', "Directory '#{ARGV.first}' already exists."
19
41
  exit
20
42
  end
21
43
 
@@ -26,13 +48,17 @@ cd app_name
26
48
  mkdir_p ['views', 'public/javascripts', 'public/stylesheets', 'public/images']
27
49
 
28
50
  File.open "#{app_name}.rb", 'w' do |f|
29
- puts " \033[32mnew\033[0m\ #{app_name}.rb"
51
+ say 'new', "#{app_name}.rb"
52
+
30
53
  f << "# encoding: utf-8\n"
31
54
  f << "\n"
32
55
  f << "require 'sinatra'\n"
33
56
  f << "require 'data_mapper'\n" if @datamapper
57
+ f << "require 'erb'\n" if @erb
34
58
  f << "require 'haml'\n" if @haml
35
- f << "require 'sass'\n" if @sass
59
+ f << "require 'sass'\n" if @sass || @scss
60
+ f << "require 'RedCloth' \n" if @textile
61
+ f << "require 'rdiscount'\n" if @markdown
36
62
  f << "\n"
37
63
  f << "use Rack::MethodOverride\n"
38
64
  f << "\n"
@@ -44,9 +70,10 @@ File.open "#{app_name}.rb", 'w' do |f|
44
70
  f << "end\n"
45
71
  f << "\n"
46
72
  end
47
- if @sass
73
+ if @sass || @scss
48
74
  f << "get '/stylesheets/application.css' do\n"
49
- f << " sass :stylesheet, :style => :expanded\n"
75
+ f << " sass :stylesheet, :style => :expanded\n" if @sass
76
+ f << " scss :stylesheet, :style => :expanded\n" if @scss
50
77
  f << "end\n"
51
78
  f << "\n"
52
79
  end
@@ -57,7 +84,8 @@ File.open "#{app_name}.rb", 'w' do |f|
57
84
  end
58
85
 
59
86
  File.open 'config.ru', 'w' do |f|
60
- puts " \033[32mnew\033[0m\ config.ru"
87
+ say 'new', 'config.ru'
88
+
61
89
  f << "# encoding: utf-8\n"
62
90
  f << "\n"
63
91
  f << "require 'sinatra'\n"
@@ -67,19 +95,22 @@ File.open 'config.ru', 'w' do |f|
67
95
  end
68
96
 
69
97
  File.open 'Gemfile', 'w' do |f|
70
- puts " \033[32mnew\033[0m\ Gemfile"
98
+ say 'new', 'Gemfile'
99
+
71
100
  f << "source :rubygems\n"
72
101
  f << "\n"
73
102
  f << "gem 'sinatra'\n"
74
103
  f << "gem 'data_mapper'\n" if @datamapper
75
104
  f << "gem 'haml'\n" if @haml
76
- f << "gem 'sass\n" if @sass
77
- f << "gem 'RedCloth'\n"
105
+ f << "gem 'sass'\n" if @sass
106
+ f << "gem 'RedCloth'\n" if @textile
107
+ f << "gem 'rdiscount'\n" if @markdown
78
108
  end
79
109
 
80
110
  if @haml
81
111
  File.open './views/layout.haml', 'w' do |f|
82
- puts " \033[32mnew\033[0m\ views/layout.haml"
112
+ say 'new', 'views/layout.haml'
113
+
83
114
  f << "!!!\n"
84
115
  f << "%html\n"
85
116
  f << " %head\n"
@@ -95,11 +126,12 @@ if @haml
95
126
  end
96
127
 
97
128
  touch './views/index.haml'
98
- puts " \033[32mnew\033[0m\ views/index.haml"
129
+ say 'new', 'views/index.haml'
99
130
 
100
131
  elsif @erb
101
132
  File.open './views/layout.erb', 'w' do |f|
102
- puts " \033[32mnew\033[0m\ views/layout.erb"
133
+ say 'new', 'views/layout.erb'
134
+
103
135
  f << "<!DOCTYPE html>\n"
104
136
  f << "<html>\n"
105
137
  f << " <head>\n"
@@ -118,24 +150,34 @@ elsif @erb
118
150
  end
119
151
 
120
152
  touch './views/index.erb'
121
- puts " \033[32mnew\033[0m\ views/index.erb"
153
+ say 'new', 'views/index.erb'
122
154
  end
123
155
 
124
156
  File.open './public/stylesheets/reset.css', 'w' do |f|
125
- puts " \033[32mnew\033[0m\ public/stylesheets/reset.css"
157
+ say 'new', 'public/stylesheets/reset.css'
158
+
126
159
  f << open('http://meyerweb.com/eric/tools/css/reset/reset.css').read
127
160
  end if @reset
128
161
 
129
162
  File.open './views/application.sass', 'w' do |f|
130
- puts " \033[32mnew\033[0m\ public/application.sass"
131
- end
163
+ say 'new', 'views/application.sass'
164
+ end if @sass
165
+
166
+ File.open './views/application.scss', 'w' do |f|
167
+ say 'new', 'views/application.scss'
168
+ end if @scss
169
+
170
+ File.open './public/stylesheets/application.css', 'w' do |f|
171
+ say 'new', 'public/stylesheets/application.css'
172
+ end unless @sass || @scss
132
173
 
133
174
  touch './public/javascripts/application.js'
134
- puts " \033[32mnew\033[0m\ public/javascripts/application.js"
175
+ say 'new', 'public/javascripts/application.js'
135
176
 
136
177
  if @jquery
137
178
  File.open './public/javascripts/jquery.min.js', 'w' do |f|
138
- puts " \033[32mnew\033[0m\ public/javascripts/jquery.min.js"
179
+ say 'new', 'public/javascripts/jquery.min.js'
180
+
139
181
  f << open('http://code.jquery.com/jquery.min.js').read
140
182
  end
141
183
 
@@ -148,7 +190,13 @@ if @jquery
148
190
  end
149
191
  elsif @prototype
150
192
  File.open './public/javascripts/prototype.js', 'w' do |f|
151
- puts " \033[32mnew\033[0m\ public/javascripts/prototype.js"
193
+ say 'new', 'public/javascripts/prototype.js'
194
+
152
195
  f << open('https://ajax.googleapis.com/ajax/libs/prototype/1.7.0.0/prototype.js').read
153
196
  end
197
+ end
198
+
199
+ if @git
200
+ say 'new', '.git'
201
+ system 'git init --quiet ; git add .'
154
202
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: create
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -18,6 +18,7 @@ executables:
18
18
  extensions: []
19
19
  extra_rdoc_files: []
20
20
  files:
21
+ - README.textile
21
22
  - create.gemspec
22
23
  - lib/create.rb
23
24
  - bin/create