Class: Palco::Application
Constant Summary collapse
- FILE_LIST =
[ {:name=>'README', :file=>true}, {:name=>'LICENSE', :file=>true}, {:name=>'Gemfile', :file=>true}, {:name=>'app.rb', :file=>true}, {:name=>'config.ru', :file=>true}, {:name=>'conf', :file=>false}, {:name=>'lib', :file=>false}, {:name=>'lib/version.rb', :file=>true}, {:name=>'spec', :file=>false}, {:name=>'public', :file=>false}, {:name=>'views', :file=>false}, {:name=>'logs', :file=>false}, {:name=>'spec/spec_helper.rb', :file=>true}, ]
Instance Attribute Summary
Attributes inherited from Base
#generated, #items_list, #project_name, #valid
Instance Method Summary collapse
- #generate ⇒ Object
-
#initialize(name) ⇒ Application
constructor
Public: creates a new Sinatra modular application skeleton.
Methods inherited from Base
#can_generate?, #destroy, #generated?, #valid?
Constructor Details
#initialize(name) ⇒ Application
Public: creates a new Sinatra modular application skeleton.
The directory layout is based only on my personal taste so feel free to override Palco:Base with your own personal template or even suggest me how to improve this one.
What we absolutely need here is an app.rb file for the main code and a lib directory for other auxiliary helpers. We need a views directory for templates and a public directory for static assests.
Since I love haml as template language I choose that as default.
Example
app = Palco::Application.new('a_new_app')
app.generate
Returns
A new Sinatra modular application. Fire up rackup or shotgun and start
hacking.
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/palco/application.rb', line 40 def initialize(name) @r = name list = FILE_LIST list = list << {:name=>"lib/#{name}", :file=>false} list = list << {:name=>"spec/#{name}_spec.rb", :file=>true} super(name, list) end |
Instance Method Details
#generate ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/palco/application.rb', line 52 def generate super license = Palco::License.new(@r) license.create file = Palco::FileBase.new(@r, "lib/#{@r}/version.rb") file.file_content = "module #{@r.capitalize}\nVERSION=\"0.0.0\"\nend\n" file.create file = Palco::FileBase.new(@r, "spec/spec_helper.rb") file.file_content = "require '#{@r}'\n" file.create file = Palco::FileBase.new(@r, "app.rb") file.file_content = "require 'sinatra/base'\nclass #{@r.capitalize} < Sinatra::Base\n# ... app code here ... \n\n # start the server if execute this file directly\n run! if app_file == $0\nend\n" file.create file = Palco::FileBase.new(@r, "config.ru") file.file_content = "require './app'\nlog = File.new(\"logs/#{@r}.log\", \"a\")\nSTDOUT.reopen(log)\nSTDERR.reopen(log)\nrun #{@r.capitalize}::App\n" file.create end |