Class: Camping::Generators

Inherits:
Object show all
Defined in:
lib/camping/commands.rb

Class Method Summary collapse

Class Method Details

.make_camp_file(app_name = "Tent") ⇒ Object



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/camping/commands.rb', line 154

def make_camp_file(app_name="Tent")
  write "camp.rb", "require 'camping'\n\nCamping.goes :\#{app_name}\n\nmodule \#{app_name}\n  module Models\n  end\n\n  module Controllers\n    class Index\ndef get\n  @title = \"\#{app_name}\"\n  render :index\nend\n    end\n  end\n\n  module Helpers\n  end\n\n  module Views\n\n    def layout\nhtml do\n  head do\n    title '\#{app_name}'\n    link :rel => 'stylesheet', :type => 'text/css',\n    :href => '/styles.css', :media => 'screen'\n  end\n  body do\n    h1 '\#{app_name}'\n\n    div.wrapper! do\n      self << yield\n    end\n  end\nend\n    end\n\n    def index\nh2 \"Let's go Camping\"\n    end\n\n  end\n\nend\n\n"
end

.make_configkdlObject

write a config.kdl



247
248
249
250
251
252
# File 'lib/camping/commands.rb', line 247

def make_configkdl
  write 'config.kdl', "// config.kdl\nhostname \"localhost\"\n"
end

.make_gemfileObject

write a Gemfile



255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
# File 'lib/camping/commands.rb', line 255

def make_gemfile
  write 'Gemfile', "# frozen_string_literal: true\nsource 'https://rubygems.org'\n\ngem 'camping'\ngem 'puma'\ngem 'rake'\n\ngroup :production do\n  gem 'rack-ssl-enforcer'\nend\n\ngroup :development do\nend\n\ngroup :test do\n  gem 'minitest', '~> 5.0'\n  gem 'minitest-reporters'\n  gem 'rack-test'\n  gem 'minitest-hooks'\nend\n\n"
end

.make_gitignoreObject

makes a gitignore.



207
208
209
210
211
212
213
214
215
216
# File 'lib/camping/commands.rb', line 207

def make_gitignore
  write '.gitignore', ".DS_Store\nnode_modules/\ntmp/\ndb/camping.db\ndb/camping.sqlite3\ndb/camping.sqlite\n"
end

.make_public_folderObject



294
295
296
# File 'lib/camping/commands.rb', line 294

def make_public_folder
  Dir.mkdir("public") unless Dir.exist?("public")
end

.make_rakefileObject

writes a rakefile



225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
# File 'lib/camping/commands.rb', line 225

def make_rakefile
  write 'Rakefile', "# Rakefile\nrequire 'rake'\nrequire 'rake/clean'\nrequire 'rake/testtask'\nrequire 'tempfile'\nrequire 'open3'\n\ntask :default => :test\ntask :test => 'test:all'\n\nnamespace 'test' do\n  Rake::TestTask.new('all') do |t|\n    t.libs << 'test'\n    t.test_files = FileList['test/test_*.rb']\n  end\nend\n"
end

.make_readmeObject

write a README.md



282
283
284
285
286
287
288
289
290
291
292
# File 'lib/camping/commands.rb', line 282

def make_readme
  write 'README.md', "# Camping\nCamping is really fun and I hope you enjoy it.\n\nStart camping by running: `camping` in the root directory.\n\nTo start Camping in development mode run: `camping -e development\n\n"
end

.make_ruby_versionObject



218
219
220
221
222
# File 'lib/camping/commands.rb', line 218

def make_ruby_version
  write '.ruby-version', "\#{RUBY_VERSION}\n"
end

.make_test_folderObject



298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
# File 'lib/camping/commands.rb', line 298

def make_test_folder
  Dir.mkdir("test") unless Dir.exist?("test")
  write 'test/test_helper.rb', "$:.unshift File.dirname(__FILE__) + '/../'\n# shift to act like we're in the regular degular directory\n\nbegin\n  require 'rubygems'\nrescue LoadError\nend\n\nrequire 'camping'\nrequire 'minitest/autorun'\nrequire 'minitest'\nrequire 'rack/test'\nrequire \"minitest/reporters\"\nMinitest::Reporters.use! [Minitest::Reporters::DefaultReporter.new(:color => true)]\n\nclass TestCase < Minitest::Test\n  include Rack::Test::Methods\n\n  def self.inherited(mod)\n    mod.app = Object.const_get(mod.to_s[/\\w+/])\n    super\n  end\n\n  class << self\n    attr_accessor :app\n  end\n\n  def body() last_response.body end\n  def app()  self.class.app     end\n\n  def assert_reverse\n    begin\nyield\n    rescue Exception\n    else\nassert false, \"Block didn't fail\"\n    end\n  end\n\n  def assert_body(str)\n    case str\n    when Regexp\nassert_match(str, last_response.body.strip)\n    else\nassert_equal(str.to_s, last_response.body.strip)\n    end\n  end\n\n  def assert_status(code)\n    assert_equal(code, last_response.status)\n  end\n\n  def test_silly; end\n\nend\n\n"
end

.read(file) ⇒ Object

read a file



150
151
152
# File 'lib/camping/commands.rb', line 150

def read(file)
  File.read(file)
end

.write(file, content) ⇒ Object

write a file



142
143
144
145
146
147
# File 'lib/camping/commands.rb', line 142

def write(file, content)
  raise "Cannot write to nil file." unless file
  folder = File.dirname(file)
  `mkdir -p #{folder}` unless File.exist?(folder)
  File.open(file, 'w') { |f| f.write content }
end