Class: Camping::Generators
Class Method Summary collapse
- .make_camp_file(app_name = "Tent") ⇒ Object
-
.make_configkdl ⇒ Object
write a config.kdl.
-
.make_gemfile ⇒ Object
write a Gemfile.
-
.make_gitignore ⇒ Object
makes a gitignore.
- .make_public_folder ⇒ Object
-
.make_rakefile ⇒ Object
writes a rakefile.
-
.make_readme ⇒ Object
write a README.md.
- .make_ruby_version ⇒ Object
- .make_test_folder ⇒ Object
-
.read(file) ⇒ Object
read a file.
-
.write(file, content) ⇒ Object
write a file.
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", <<-RUBY require 'camping' Camping.goes :#{app_name} module #{app_name} module Models end module Controllers class Index def get @title = "#{app_name}" render :index end end end module Helpers end module Views def layout html do head do title '#{app_name}' link :rel => 'stylesheet', :type => 'text/css', :href => '/styles.css', :media => 'screen' end body do h1 '#{app_name}' div.wrapper! do self << yield end end end end def index h2 "Let's go Camping" end end end RUBY end |
.make_configkdl ⇒ Object
write a config.kdl
247 248 249 250 251 252 |
# File 'lib/camping/commands.rb', line 247 def make_configkdl write 'config.kdl', <<-KDL // config.kdl hostname "localhost" KDL end |
.make_gemfile ⇒ Object
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', <<-GEM # frozen_string_literal: true source 'https://rubygems.org' gem 'camping' gem 'puma' gem 'rake' group :production do gem 'rack-ssl-enforcer' end group :development do end group :test do gem 'minitest', '~> 5.0' gem 'minitest-reporters' gem 'rack-test' gem 'minitest-hooks' end GEM end |
.make_gitignore ⇒ Object
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', <<-GIT .DS_Store node_modules/ tmp/ db/camping.db db/camping.sqlite3 db/camping.sqlite GIT end |
.make_public_folder ⇒ Object
294 295 296 |
# File 'lib/camping/commands.rb', line 294 def make_public_folder Dir.mkdir("public") unless Dir.exist?("public") end |
.make_rakefile ⇒ Object
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', <<-TXT # Rakefile require 'rake' require 'rake/clean' require 'rake/testtask' require 'tempfile' require 'open3' task :default => :test task :test => 'test:all' namespace 'test' do Rake::TestTask.new('all') do |t| t.libs << 'test' t.test_files = FileList['test/test_*.rb'] end end TXT end |
.make_readme ⇒ Object
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', <<-READ # Camping Camping is really fun and I hope you enjoy it. Start camping by running: `camping` in the root directory. To start Camping in development mode run: `camping -e development READ end |
.make_ruby_version ⇒ Object
218 219 220 221 222 |
# File 'lib/camping/commands.rb', line 218 def make_ruby_version write '.ruby-version', <<-RUBY #{RUBY_VERSION} RUBY end |
.make_test_folder ⇒ Object
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', <<-RUBY $:.unshift File.dirname(__FILE__) + '/../' # shift to act like we're in the regular degular directory begin require 'rubygems' rescue LoadError end require 'camping' require 'minitest/autorun' require 'minitest' require 'rack/test' require "minitest/reporters" Minitest::Reporters.use! [Minitest::Reporters::DefaultReporter.new(:color => true)] class TestCase < Minitest::Test include Rack::Test::Methods def self.inherited(mod) mod.app = Object.const_get(mod.to_s[/\w+/]) super end class << self attr_accessor :app end def body() last_response.body end def app() self.class.app end def assert_reverse begin yield rescue Exception else assert false, "Block didn't fail" end end def assert_body(str) case str when Regexp assert_match(str, last_response.body.strip) else assert_equal(str.to_s, last_response.body.strip) end end def assert_status(code) assert_equal(code, last_response.status) end def test_silly; end end RUBY 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 |