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_assets ⇒ Object
Returns the value of attribute css_assets.
-
#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_assets ⇒ Object
Returns the value of attribute js_assets.
-
#js_path ⇒ Object
Returns the value of attribute js_path.
-
#libs ⇒ Object
Returns the value of attribute libs.
-
#livereload ⇒ Object
Returns the value of attribute livereload.
-
#no_overwrite ⇒ Object
Returns the value of attribute no_overwrite.
-
#path ⇒ Object
Returns the value of attribute path.
-
#public_dir ⇒ Object
Returns the value of attribute public_dir.
-
#run_bundle ⇒ Object
Returns the value of attribute run_bundle.
-
#sass ⇒ Object
Returns the value of attribute sass.
-
#skip_index ⇒ Object
Returns the value of attribute skip_index.
-
#sorted_libs ⇒ Object
Returns the value of attribute sorted_libs.
-
#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.
- #bundle ⇒ Object
- #collect_libraries ⇒ Object
- #create_asset_file ⇒ Object
- #create_gemfile ⇒ 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
-
#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.
-
#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.
- #render_template(source, dest) ⇒ Object
-
#set_paths ⇒ Object
Set up the basic paths we’ll use throughout.
- #template_root ⇒ Object
- #uses_jquery? ⇒ Boolean
- #vendor_root ⇒ Object
Methods included from Helpers
#cp, #cp_r, #create_file, #mkdir_p, #render_template_to_file
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?
38 39 40 41 42 |
# File 'lib/qedproject/project.rb', line 38 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_assets ⇒ Object
Returns the value of attribute css_assets.
9 10 11 |
# File 'lib/qedproject/project.rb', line 9 def css_assets @css_assets 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_assets ⇒ Object
Returns the value of attribute js_assets.
9 10 11 |
# File 'lib/qedproject/project.rb', line 9 def js_assets @js_assets 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 |
#livereload ⇒ Object
Returns the value of attribute livereload.
9 10 11 |
# File 'lib/qedproject/project.rb', line 9 def livereload @livereload end |
#no_overwrite ⇒ Object
Returns the value of attribute no_overwrite.
9 10 11 |
# File 'lib/qedproject/project.rb', line 9 def no_overwrite @no_overwrite end |
#path ⇒ Object
Returns the value of attribute path.
9 10 11 |
# File 'lib/qedproject/project.rb', line 9 def path @path end |
#public_dir ⇒ Object
Returns the value of attribute public_dir.
9 10 11 |
# File 'lib/qedproject/project.rb', line 9 def public_dir @public_dir end |
#run_bundle ⇒ Object
Returns the value of attribute run_bundle.
9 10 11 |
# File 'lib/qedproject/project.rb', line 9 def run_bundle @run_bundle end |
#sass ⇒ Object
Returns the value of attribute sass.
9 10 11 |
# File 'lib/qedproject/project.rb', line 9 def sass @sass end |
#skip_index ⇒ Object
Returns the value of attribute skip_index.
9 10 11 |
# File 'lib/qedproject/project.rb', line 9 def skip_index @skip_index end |
#sorted_libs ⇒ Object
Returns the value of attribute sorted_libs.
9 10 11 |
# File 'lib/qedproject/project.rb', line 9 def sorted_libs @sorted_libs 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.
16 17 18 |
# File 'lib/qedproject/project.rb', line 16 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
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/qedproject/project.rb', line 140 def add_testing mkdir_p File.join(self.path, "spec"), :verbose => self.verbose cp_r File.join(self.vendor_root, "jasmine", "lib"), File.join(self.path, "spec", "lib"), :verbose => self.verbose if self.uses_jquery? cp_r File.join(self.vendor_root, "jasmine-jquery", "jasmine-jquery.js"), File.join(self.path, "spec", "lib"), :verbose => self.verbose end render_template_to_file "suite.html", File.join(self.path, "spec", "SpecRunner.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 |
#bundle ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/qedproject/project.rb', line 44 def bundle Dir.chdir(self.path) do puts "Bundling assets" `bundle install` end end |
#collect_libraries ⇒ 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 76 77 78 79 80 81 82 |
# File 'lib/qedproject/project.rb', line 52 def collect_libraries self.css_assets = [] self.js_assets = [] self.sorted_libs = [] self.libs.each do |requested_library| raise QEDProject::BadLibraryError, "#{requested_library} is not a valid library" unless QEDProject::Libraries::Base.libs.include? requested_library library = QEDProject::Libraries::Base.libs[requested_library] if library.respond_to? :dependencies dependencies = library.dependencies dependencies.each do |d| unless self.sorted_libs.include?(d) self.sorted_libs << d end end end unless self.sorted_libs.include?(requested_library) self.sorted_libs << requested_library end end self.sorted_libs.each do |lib| library = QEDProject::Libraries::Base.libs[lib] self.js_assets += library.js_files if library.respond_to?(:js_files) self.css_assets += library.css_files if library.respond_to?(:css_files) end end |
#create_asset_file ⇒ Object
203 204 205 |
# File 'lib/qedproject/project.rb', line 203 def create_asset_file render_template("assets.yml", File.join(self.path, "config", "assets.yml")) end |
#create_gemfile ⇒ Object
220 221 222 |
# File 'lib/qedproject/project.rb', line 220 def create_gemfile render_template "Gemfile", File.join(self.path, "Gemfile") end |
#create_guardfile ⇒ Object
207 208 209 |
# File 'lib/qedproject/project.rb', line 207 def create_guardfile render_template "Guardfile", File.join(self.path, "Guardfile") end |
#create_index ⇒ Object
211 212 213 214 |
# File 'lib/qedproject/project.rb', line 211 def create_index @project = self render_template "index.html", File.join(self.path, self.public_dir, "index.html") unless self.skip_index 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
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/qedproject/project.rb', line 170 def create_project_skeleton mkdir_p( self.path, :verbose => self.verbose) mkdir_p( File.join(self.path, self.public_dir), :verbose => self.verbose) mkdir_p( File.join(self.path, self.images_path), :verbose => self.verbose) mkdir_p( File.join(self.path, "_qedtmp"), :verbose => self.verbose) mkdir_p( File.join(self.path, self.js_path), :verbose => self.verbose) mkdir_p( File.join(self.path, self.css_path), :verbose => self.verbose) mkdir_p( File.join(self.path, "config"), :verbose => self.verbose) if self.needs_config_folder? if self.coffeescript mkdir_p( File.join(self.path, "coffeescripts"), :verbose => self.verbose) create_file(File.join(self.path, "coffeescripts", "app.coffee"), :verbose => self.verbose, :no_overwrite => self.no_overwrite) else create_file(File.join(self.path, self.js_path, "app.js" ), :verbose => self.verbose, :no_overwrite => self.no_overwrite) end if self.sass mkdir_p( File.join(self.path, "sass"), :verbose => self.verbose) create_file( File.join(self.path, "sass", "app.sass"), :verbose => self.verbose, :no_overwrite => self.no_overwrite) else create_file(File.join(self.path, self.css_path, "app.css" ), :verbose => self.verbose, :no_overwrite => self.no_overwrite) end end |
#create_rakefile ⇒ Object
216 217 218 |
# File 'lib/qedproject/project.rb', line 216 def create_rakefile render_template "Rakefile", File.join(self.path, "Rakefile") 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
126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/qedproject/project.rb', line 126 def generate self.create_project_skeleton self.create_index unless self.skip_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 self.create_gemfile self.bundle if self.run_bundle end |
#get_libraries ⇒ Object
Loop through the libraries the user added and run their generate methods which pulls in the additional optional files.
195 196 197 198 199 200 201 |
# File 'lib/qedproject/project.rb', line 195 def get_libraries self.sorted_libs.each do |lib| library = QEDProject::Libraries::Base.libs[lib] l = library.new(self) l.generate! end end |
#needs_config_folder? ⇒ Boolean
Only jammit needs a config folder for now.
116 117 118 |
# File 'lib/qedproject/project.rb', line 116 def needs_config_folder? self.jammit end |
#needs_guardfile? ⇒ Boolean
We need a guardfile if the user is using jammit, sass, or coffeescript.
111 112 113 |
# File 'lib/qedproject/project.rb', line 111 def needs_guardfile? self.jammit || self.sass || self.coffeescript || self.livereload end |
#process_options(options) ⇒ Object
Sets instance methods with values from the options hash.
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/qedproject/project.rb', line 85 def () self.libs = [:libs] || [] collect_libraries self.public_dir = [:public_dir] || "public" self.jammit = [:jammit] self.sass = [:sass] self.coffeescript = [:coffeescript] self.verbose = [:verbose] self.testing = [:testing] self.skip_index = [:skip_index] self.livereload = [:livereload] self.no_overwrite = [:no_overwrite] ? true : false self.run_bundle = [:bundle] end |
#render_template(source, dest) ⇒ Object
224 225 226 227 228 229 230 231 |
# File 'lib/qedproject/project.rb', line 224 def render_template(source, dest) if self.no_overwrite && File.exist?(dest) puts "Skipping #{dest}" if self.verbose else render_template_to_file source, dest, binding puts "Created #{dest}" if self.verbose end end |
#set_paths ⇒ Object
Set up the basic paths we’ll use throughout
104 105 106 107 108 |
# File 'lib/qedproject/project.rb', line 104 def set_paths self.images_path = File.join(self.public_dir, "images") self.js_path = self.jammit ? "javascripts" : File.join(self.public_dir, "javascripts") self.css_path = self.jammit ? "stylesheets" : File.join(self.public_dir, "stylesheets") end |
#template_root ⇒ Object
20 21 22 |
# File 'lib/qedproject/project.rb', line 20 def template_root File.("../../../templates", __FILE__) end |
#uses_jquery? ⇒ Boolean
28 29 30 |
# File 'lib/qedproject/project.rb', line 28 def uses_jquery? self.libs.include?(:jquery) end |
#vendor_root ⇒ Object
24 25 26 |
# File 'lib/qedproject/project.rb', line 24 def vendor_root File.("../../../vendor", __FILE__) end |