Class: QEDProject::Project
- Inherits:
-
Object
- Object
- QEDProject::Project
- Includes:
- Helpers
- Defined in:
- lib/qedproject/project.rb
Instance Attribute Summary collapse
-
#coffeescript ⇒ Object
Returns the value of attribute coffeescript.
-
#css_path ⇒ Object
Returns the value of attribute css_path.
-
#images_path ⇒ Object
Returns the value of attribute images_path.
-
#jammit ⇒ Object
Returns the value of attribute jammit.
-
#js_path ⇒ Object
Returns the value of attribute js_path.
-
#libs ⇒ Object
Returns the value of attribute libs.
-
#path ⇒ Object
Returns the value of attribute path.
-
#sass ⇒ Object
Returns the value of attribute sass.
-
#testing ⇒ Object
Returns the value of attribute testing.
-
#verbose ⇒ Object
Returns the value of attribute verbose.
Class Method Summary collapse
-
.create(project_path, options = {}) ⇒ Object
convenience method to create a new project.
Instance Method Summary collapse
-
#add_testing ⇒ Object
includes the Jasmine BDD framework for javascript testing.
- #create_asset_file ⇒ Object
- #create_guardfile ⇒ Object
- #create_index ⇒ Object
-
#create_project_skeleton ⇒ Object
Set up the main project skeleton project public/ assets/ * only with assets images/ javascripts/ * only without assets stylesheets/ * only without assets config/ assets.yml * optional coffeescripts/ * optional sass/ * optional spec/ * optional Guardfile * optional.
- #create_rakefile ⇒ Object
-
#css_assets ⇒ Object
Convenience method for showing all of the css files that the project should contain.
-
#generate ⇒ Object
Start the project generation.
-
#get_libraries ⇒ Object
Loop through the libraries the user added and run their generate methods which pulls in the additional optional files.
-
#initialize(project_path, options = {}) ⇒ Project
constructor
Creates a new Project instance.
-
#js_assets ⇒ Object
Convenience method for showing all of the JavaScript files that the project should contain.
-
#needs_config_folder? ⇒ Boolean
Only jammit needs a config folder for now.
-
#needs_guardfile? ⇒ Boolean
We need a guardfile if the user is using jammit, sass, or coffeescript.
-
#process_options(options) ⇒ Object
Sets instance methods with values from the options hash.
-
#set_paths ⇒ Object
Set up the basic paths we’ll use throughout.
- #template_root ⇒ Object
- #vendor_root ⇒ Object
Methods included from Helpers
Constructor Details
#initialize(project_path, options = {}) ⇒ Project
Creates a new Project instance. Options:
:libs : A list of js libraries to include, Can be :backbone, :jquery, :knockout
:jammit: boolean, should Jammit be included?
:coffeescript : Should CoffeeScript support be included?
:sass Should sass support be included?
31 32 33 34 35 |
# File 'lib/qedproject/project.rb', line 31 def initialize(project_path, = {}) self.path = project_path self.() self.set_paths end |
Instance Attribute Details
#coffeescript ⇒ Object
Returns the value of attribute coffeescript.
9 10 11 |
# File 'lib/qedproject/project.rb', line 9 def coffeescript @coffeescript end |
#css_path ⇒ Object
Returns the value of attribute css_path.
9 10 11 |
# File 'lib/qedproject/project.rb', line 9 def css_path @css_path end |
#images_path ⇒ Object
Returns the value of attribute images_path.
9 10 11 |
# File 'lib/qedproject/project.rb', line 9 def images_path @images_path end |
#jammit ⇒ Object
Returns the value of attribute jammit.
9 10 11 |
# File 'lib/qedproject/project.rb', line 9 def jammit @jammit end |
#js_path ⇒ Object
Returns the value of attribute js_path.
9 10 11 |
# File 'lib/qedproject/project.rb', line 9 def js_path @js_path end |
#libs ⇒ Object
Returns the value of attribute libs.
9 10 11 |
# File 'lib/qedproject/project.rb', line 9 def libs @libs end |
#path ⇒ Object
Returns the value of attribute path.
9 10 11 |
# File 'lib/qedproject/project.rb', line 9 def path @path end |
#sass ⇒ Object
Returns the value of attribute sass.
9 10 11 |
# File 'lib/qedproject/project.rb', line 9 def sass @sass end |
#testing ⇒ Object
Returns the value of attribute testing.
9 10 11 |
# File 'lib/qedproject/project.rb', line 9 def testing @testing end |
#verbose ⇒ Object
Returns the value of attribute verbose.
9 10 11 |
# File 'lib/qedproject/project.rb', line 9 def verbose @verbose end |
Class Method Details
.create(project_path, options = {}) ⇒ Object
convenience method to create a new project. Simply call create with the project path and the options.
13 14 15 |
# File 'lib/qedproject/project.rb', line 13 def self.create(project_path, = {}) self.new(project_path, ).generate end |
Instance Method Details
#add_testing ⇒ Object
includes the Jasmine BDD framework for javascript testing
113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/qedproject/project.rb', line 113 def add_testing FileUtils.mkdir_p File.join(self.path, "spec"), :verbose => self.verbose FileUtils.cp_r File.join(self.vendor_root, "jasmine", "lib"), File.join(self.path, "spec", "lib"), :verbose => self.verbose render_template_to_file "suite.html", File.join(self.path, "spec", "suite.html"), binding if self.coffeescript render_template_to_file "sampleSpec.coffee", File.join(self.path, "spec", "sampleSpec.coffee"), binding else render_template_to_file "sampleSpec.js", File.join(self.path, "spec", "sampleSpec.js"), binding end end |
#create_asset_file ⇒ Object
164 165 166 167 |
# File 'lib/qedproject/project.rb', line 164 def create_asset_file render_template_to_file("assets.yml", File.join(self.path, "config", "assets.yml"), binding) puts "Created #{File.join(self.path, 'config', 'assets.yml')}" if self.verbose end |
#create_guardfile ⇒ Object
169 170 171 172 |
# File 'lib/qedproject/project.rb', line 169 def create_guardfile render_template_to_file "Guardfile", File.join(self.path, "Guardfile"), binding puts "Created #{ File.join(self.path, "Guardfile")}" if self.verbose end |
#create_index ⇒ Object
174 175 176 177 178 |
# File 'lib/qedproject/project.rb', line 174 def create_index @project = self render_template_to_file "index.html", File.join(self.path, "public", "index.html"), binding puts "Created #{ File.join(self.path, "public", "index.html")}" if self.verbose end |
#create_project_skeleton ⇒ Object
Set up the main project skeleton project
public/
assets/ * only with assets
images/
javascripts/ * only without assets
stylesheets/ * only without assets
config/
assets.yml * optional
coffeescripts/ * optional
sass/ * optional
spec/ * optional
Guardfile * optional
141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/qedproject/project.rb', line 141 def create_project_skeleton ::FileUtils.mkdir_p( self.path, :verbose => self.verbose) ::FileUtils.mkdir_p( File.join(self.path, "public"), :verbose => self.verbose) ::FileUtils.mkdir_p( File.join(self.path, self.images_path), :verbose => self.verbose) ::FileUtils.mkdir_p( File.join(self.path, "tmp"), :verbose => self.verbose) ::FileUtils.mkdir_p( File.join(self.path, self.js_path), :verbose => self.verbose) ::FileUtils.mkdir_p( File.join(self.path, self.css_path), :verbose => self.verbose) ::FileUtils.mkdir_p( File.join(self.path, "config"), :verbose => self.verbose) if self.needs_config_folder? ::FileUtils.mkdir_p( File.join(self.path, "coffeescripts"), :verbose => self.verbose) if self.coffeescript ::FileUtils.mkdir_p( File.join(self.path, "sass"), :verbose => self.verbose) if self.sass end |
#create_rakefile ⇒ Object
180 181 182 183 |
# File 'lib/qedproject/project.rb', line 180 def create_rakefile render_template_to_file "Rakefile", File.join(self.path, "Rakefile"), binding puts "Created #{ File.join(self.path, "Rakefile")}" if self.verbose end |
#css_assets ⇒ Object
Convenience method for showing all of the css files that the project should contain. Good for creating asset lists and loading files in rendered templates
54 55 56 57 58 59 60 61 62 |
# File 'lib/qedproject/project.rb', line 54 def css_assets libs.inject([]) do |original, lib| if QEDProject::Libraries::Base.libs[lib].respond_to?(:css_files) original += QEDProject::Libraries::Base.libs[lib].css_files else original end end end |
#generate ⇒ Object
Start the project generation. Create the folder Get all of the libraries create an assets file if needed add the testing folder if needed create a guardfile if needed
102 103 104 105 106 107 108 109 110 |
# File 'lib/qedproject/project.rb', line 102 def generate self.create_project_skeleton self.create_index self.get_libraries if self.libs self.create_asset_file if self.jammit self.add_testing if self.testing self.create_guardfile if self.needs_guardfile? self.create_rakefile end |
#get_libraries ⇒ Object
Loop through the libraries the user added and run their generate methods which pulls in the additional optional files.
156 157 158 159 160 161 162 |
# File 'lib/qedproject/project.rb', line 156 def get_libraries libs.each do |lib| library = QEDProject::Libraries::Base.libs[lib] l = library.new(self) l.generate! end end |
#js_assets ⇒ Object
Convenience method for showing all of the JavaScript files that the project should contain. Good for creating asset lists and loading files in rendered templates
41 42 43 44 45 46 47 48 49 |
# File 'lib/qedproject/project.rb', line 41 def js_assets libs.inject([]) do |original, lib| if QEDProject::Libraries::Base.libs[lib].respond_to?(:js_files) original += QEDProject::Libraries::Base.libs[lib].js_files else original end end end |
#needs_config_folder? ⇒ Boolean
Only jammit needs a config folder for now.
92 93 94 |
# File 'lib/qedproject/project.rb', line 92 def needs_config_folder? self.jammit end |
#needs_guardfile? ⇒ Boolean
We need a guardfile if the user is using jammit, sass, or coffeescript.
87 88 89 |
# File 'lib/qedproject/project.rb', line 87 def needs_guardfile? self.jammit || self.sass || self.coffeescript end |
#process_options(options) ⇒ Object
Sets instance methods with values from the options hash.
65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/qedproject/project.rb', line 65 def () self.libs = [:libs] || [] libs.each do |lib| raise QEDProject::BadLibraryError, "#{lib} is not a valid library" unless QEDProject::Libraries::Base.libs.include? lib end self.jammit = [:jammit] self.sass = [:sass] self.coffeescript = [:coffeescript] self.verbose = [:verbose] self.testing = [:testing] end |
#set_paths ⇒ Object
Set up the basic paths we’ll use throughout
80 81 82 83 84 |
# File 'lib/qedproject/project.rb', line 80 def set_paths self.images_path = File.join("public", "images") self.js_path = self.jammit ? "javascripts" : File.join("public", "javascripts") self.css_path = self.jammit ? "stylesheets" : File.join("public", "stylesheets") end |
#template_root ⇒ Object
17 18 19 |
# File 'lib/qedproject/project.rb', line 17 def template_root File.("../../../templates", __FILE__) end |
#vendor_root ⇒ Object
21 22 23 |
# File 'lib/qedproject/project.rb', line 21 def vendor_root File.("../../../vendor", __FILE__) end |