qedproject 0.0.5 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
data/bin/qedproject CHANGED
@@ -11,6 +11,7 @@ options = {}
11
11
  LIBRARIES = QEDProject::Libraries::Base.libs.keys
12
12
  OptionParser.new do |opts|
13
13
  opts.banner = "Usage: qedproject <projectname> [options]"
14
+ opts.banner << "\nAvailable Libraries are: #{LIBRARIES.join(",")}"
14
15
 
15
16
 
16
17
  opts.on('-s', '--sass', "Use SASS") do
@@ -28,10 +29,20 @@ OptionParser.new do |opts|
28
29
  opts.on('-t', '--testing', "Set up testing with Jasmine") do
29
30
  options[:testing] = true
30
31
  end
31
-
32
- opts.on("-l", "--libs [LIBRARIES]", "comma-separated list of libraries to include.\nLibraries are: #{LIBRARIES.join(",")}") do |libs|
32
+
33
+ opts.on('-p', '--public-dir [DIR]', 'Specify the name of the public folder') do |dir|
34
+ options[:public_dir] = dir
35
+ end
36
+
37
+ opts.on("-l", "--libs [LIBRARIES]", "comma-separated list of libraries to include") do |libs|
33
38
  options[:libs] = libs.split(",").collect{ |f| f.to_sym }
34
39
  end
40
+
41
+ opts.on('--skip-index', 'Skip creating a default index.html file') do
42
+ options[:skip_index] = true
43
+ end
44
+
45
+
35
46
  end.parse!
36
47
  options[:verbose] = true
37
48
  project = ARGV[0]
@@ -1,5 +1,26 @@
1
1
  module QEDProject
2
2
  module Helpers
3
+
4
+ # Copies a file - wraps FileUtils to print a nice message if verbose is on.
5
+
6
+ def cp(source, destination, options = {})
7
+ verbose = options[:verbose] || false
8
+ FileUtils.cp source, destination
9
+ puts "Created #{File.join destination, File.basename(source)}" if verbose
10
+ end
11
+
12
+ def cp_r(source, destination, options = {})
13
+ verbose = options[:verbose] || false
14
+ FileUtils.cp_r source, destination
15
+ puts "Created #{File.join destination, File.basename(source)}" if verbose
16
+ end
17
+
18
+ def mkdir_p(destination, options = {})
19
+ FileUtils.mkdir_p destination
20
+ puts "Created folder #{destination}" if verbose
21
+ end
22
+
23
+
3
24
  # Reads a template from the file system,
4
25
  # evaluates it with ERB
5
26
  # places it in the output folder specified.
@@ -13,16 +13,33 @@ module QEDProject
13
13
  # when creating the adapter.
14
14
  # Adds the library and class to QEDProject::Libraries::Base.libs hash
15
15
  # and also creates a getter method on the adapter instance
16
- def library(name)
16
+ def library(name, base_path = __FILE__)
17
17
  QEDProject::Libraries::Base.libs ||= {}
18
18
  QEDProject::Libraries::Base.libs[name] = self
19
19
  class_eval do
20
20
  define_method :library do
21
21
  name
22
22
  end
23
+
24
+ define_method :vendor_root do
25
+ File.expand_path("../../../../vendor", base_path)
26
+ end
27
+
23
28
  end
24
29
  end
25
30
 
31
+ # DSL again, this lets you specify dependencies.
32
+ # Creates a dependencies class instance method
33
+ # we can use later.
34
+ def depends_on(libraries)
35
+ m = class << self; self; end
36
+ m.send :define_method, :dependencies do
37
+ libraries
38
+ end
39
+ end
40
+
41
+ # for the DSL, creates both an instance
42
+ # method and a class instance method
26
43
  def set_js_files(files)
27
44
  # define class method
28
45
  m = class << self; self; end
@@ -72,7 +89,8 @@ module QEDProject
72
89
 
73
90
  def initialize(project)
74
91
  @project = project
75
- @lib_root = File.join(@project.vendor_root, self.library.to_s)
92
+
93
+ @lib_root = File.join(self.vendor_root, self.library.to_s)
76
94
  @template_root = File.join(@lib_root, "templates")
77
95
  end
78
96
 
@@ -84,19 +102,19 @@ module QEDProject
84
102
 
85
103
  def copy_images
86
104
  self.image_files.each do |lib|
87
- ::FileUtils.cp_r File.join(self.lib_root, lib), File.join(self.project.path, self.project.images_path), :verbose => self.project.verbose
105
+ cp_r File.join(self.lib_root, lib), File.join(self.project.path, self.project.images_path), :verbose => self.project.verbose
88
106
  end
89
107
  end
90
108
 
91
109
  def copy_css
92
110
  self.css_files.each do |lib|
93
- ::FileUtils.cp_r File.join(self.lib_root, lib), File.join(self.project.path, self.project.css_path), :verbose => self.project.verbose
111
+ cp_r File.join(self.lib_root, lib), File.join(self.project.path, self.project.css_path), :verbose => self.project.verbose
94
112
  end
95
113
  end
96
114
 
97
115
  def copy_js
98
116
  self.js_files.each do |lib|
99
- ::FileUtils.cp_r File.join(self.lib_root, lib), File.join(self.project.path, self.project.js_path), :verbose => self.project.verbose
117
+ cp_r File.join(self.lib_root, lib), File.join(self.project.path, self.project.js_path), :verbose => self.project.verbose
100
118
  end
101
119
  end
102
120
 
@@ -0,0 +1,24 @@
1
+ module QEDProject
2
+ module Libraries
3
+ class Jquerymobile < QEDProject::Libraries::Base
4
+ library :jquerymobile
5
+ depends_on [:jquery]
6
+ set_js_files ["jquery.mobile-1.0b2.js"]
7
+ set_css_files ["jquery.mobile-1.0b2.css" ]
8
+ set_image_files [
9
+ "ajax-loader.png",
10
+ "icons-18-black.png",
11
+ "icons-18-white.png",
12
+ "icons-36-black.png",
13
+ "icons-36-white.png",
14
+ "icon-search-black.png"
15
+ ]
16
+
17
+ def generate!
18
+ super
19
+ render_template_to_file "index.html", File.join(self.project.path, self.project.public_dir, "index-mobile.html"), binding
20
+ end
21
+
22
+ end
23
+ end
24
+ end
@@ -2,6 +2,7 @@ module QEDProject
2
2
  module Libraries
3
3
  class JQuerytmpl < QEDProject::Libraries::Base
4
4
  library :jquerytmpl
5
+ depends_on [:jquery]
5
6
  set_js_files ["jquery.tmpl.min.js"]
6
7
  end
7
8
  end
@@ -13,7 +13,9 @@ module QEDProject
13
13
 
14
14
  def generate!
15
15
  super
16
- render_template_to_file "index.html", File.join(self.project.path, "public", "index.html"), binding
16
+ index_file = File.join(self.project.path, self.project.public_dir, "index.html")
17
+ FileUtils.rm_rf index_file if File.exist?(index_file)
18
+ render_template_to_file "index.html", index_file, binding
17
19
  end
18
20
 
19
21
  end
@@ -0,0 +1,12 @@
1
+ module QEDProject
2
+ module Plugins
3
+
4
+ def self.load_plugins
5
+ Gem.refresh
6
+ (Gem::Specification.respond_to?(:each) ? Gem::Specification : Gem.source_index.find_name('')).each do |gem|
7
+ next if gem.name !~ /^qedproject-/
8
+ require gem.name
9
+ end
10
+ end
11
+ end
12
+ end
@@ -6,8 +6,10 @@ module QEDProject
6
6
 
7
7
  include QEDProject::Helpers
8
8
 
9
- attr_accessor :path, :libs, :coffeescript, :sass, :jammit,
10
- :js_path, :css_path, :images_path, :verbose, :testing
9
+ attr_accessor :path, :libs, :coffeescript, :sass, :jammit, :public_dir,
10
+ :js_path, :css_path, :images_path, :verbose, :testing, :skip_index,
11
+ :sorted_libs,
12
+ :css_assets, :js_assets
11
13
  # convenience method to create a new project.
12
14
  # Simply call create with the project path and the options.
13
15
  def self.create(project_path, options= {})
@@ -32,55 +34,60 @@ module QEDProject
32
34
  self.path = project_path
33
35
  self.process_options(options)
34
36
  self.set_paths
35
- end
36
-
37
-
38
- # Convenience method for showing all of the JavaScript files that
39
- # the project should contain. Good for creating asset lists
40
- # and loading files in rendered templates
41
- def js_assets
42
- libs.inject([]) do |original, lib|
43
- if QEDProject::Libraries::Base.libs[lib].respond_to?(:js_files)
44
- original += QEDProject::Libraries::Base.libs[lib].js_files
45
- else
46
- original
37
+ end
38
+
39
+ def collect_libraries
40
+
41
+ self.css_assets = []
42
+ self.js_assets = []
43
+ self.sorted_libs = []
44
+
45
+ self.libs.each do |requested_library|
46
+ raise QEDProject::BadLibraryError, "#{requested_library} is not a valid library" unless QEDProject::Libraries::Base.libs.include? requested_library
47
+ library = QEDProject::Libraries::Base.libs[requested_library]
48
+
49
+ if library.respond_to? :dependencies
50
+ dependencies = library.dependencies
51
+ dependencies.each do |d|
52
+ unless self.sorted_libs.include?(d)
53
+ self.sorted_libs << d
54
+ end
55
+ end
47
56
  end
48
- end
49
- end
50
-
51
- # Convenience method for showing all of the css files that
52
- # the project should contain. Good for creating asset lists
53
- # and loading files in rendered templates
54
- def css_assets
55
- libs.inject([]) do |original, lib|
56
- if QEDProject::Libraries::Base.libs[lib].respond_to?(:css_files)
57
- original += QEDProject::Libraries::Base.libs[lib].css_files
58
- else
59
- original
57
+
58
+ unless self.sorted_libs.include?(requested_library)
59
+ self.sorted_libs << requested_library
60
60
  end
61
61
  end
62
- end
63
-
62
+
63
+ self.sorted_libs.each do |lib|
64
+ library = QEDProject::Libraries::Base.libs[lib]
65
+ self.js_assets += library.js_files if library.respond_to?(:js_files)
66
+ self.css_assets += library.css_files if library.respond_to?(:css_files)
67
+ end
68
+
69
+ end
70
+
64
71
  # Sets instance methods with values from the options hash.
65
72
  def process_options(options)
73
+
66
74
  self.libs = options[:libs] || []
67
75
 
68
- libs.each do |lib|
69
- raise QEDProject::BadLibraryError, "#{lib} is not a valid library" unless QEDProject::Libraries::Base.libs.include? lib
70
- end
71
-
76
+ collect_libraries
77
+ self.public_dir = options[:public_dir] || "public"
72
78
  self.jammit = options[:jammit]
73
79
  self.sass = options[:sass]
74
80
  self.coffeescript = options[:coffeescript]
75
81
  self.verbose = options[:verbose]
76
82
  self.testing = options[:testing]
83
+ self.skip_index = options[:skip_index]
77
84
  end
78
85
 
79
86
  # Set up the basic paths we'll use throughout
80
87
  def set_paths
81
- self.images_path = File.join("public", "images")
82
- self.js_path = self.jammit ? "javascripts" : File.join("public", "javascripts")
83
- self.css_path = self.jammit ? "stylesheets" : File.join("public", "stylesheets")
88
+ self.images_path = File.join(self.public_dir, "images")
89
+ self.js_path = self.jammit ? "javascripts" : File.join(self.public_dir, "javascripts")
90
+ self.css_path = self.jammit ? "stylesheets" : File.join(self.public_dir, "stylesheets")
84
91
  end
85
92
 
86
93
  # We need a guardfile if the user is using jammit, sass, or coffeescript.
@@ -101,7 +108,7 @@ module QEDProject
101
108
  # create a guardfile if needed
102
109
  def generate
103
110
  self.create_project_skeleton
104
- self.create_index
111
+ self.create_index unless self.skip_index
105
112
  self.get_libraries if self.libs
106
113
  self.create_asset_file if self.jammit
107
114
  self.add_testing if self.testing
@@ -111,8 +118,8 @@ module QEDProject
111
118
 
112
119
  # includes the Jasmine BDD framework for javascript testing
113
120
  def add_testing
114
- FileUtils.mkdir_p File.join(self.path, "spec"), :verbose => self.verbose
115
- FileUtils.cp_r File.join(self.vendor_root, "jasmine", "lib"),
121
+ mkdir_p File.join(self.path, "spec"), :verbose => self.verbose
122
+ cp_r File.join(self.vendor_root, "jasmine", "lib"),
116
123
  File.join(self.path, "spec", "lib"), :verbose => self.verbose
117
124
 
118
125
 
@@ -139,22 +146,22 @@ module QEDProject
139
146
  # spec/ * optional
140
147
  # Guardfile * optional
141
148
  def create_project_skeleton
142
- ::FileUtils.mkdir_p( self.path, :verbose => self.verbose)
143
- ::FileUtils.mkdir_p( File.join(self.path, "public"), :verbose => self.verbose)
144
- ::FileUtils.mkdir_p( File.join(self.path, self.images_path), :verbose => self.verbose)
145
- ::FileUtils.mkdir_p( File.join(self.path, "tmp"), :verbose => self.verbose)
146
- ::FileUtils.mkdir_p( File.join(self.path, self.js_path), :verbose => self.verbose)
147
- ::FileUtils.mkdir_p( File.join(self.path, self.css_path), :verbose => self.verbose)
148
- ::FileUtils.mkdir_p( File.join(self.path, "config"), :verbose => self.verbose) if self.needs_config_folder?
149
- ::FileUtils.mkdir_p( File.join(self.path, "coffeescripts"), :verbose => self.verbose) if self.coffeescript
150
- ::FileUtils.mkdir_p( File.join(self.path, "sass"), :verbose => self.verbose) if self.sass
149
+ mkdir_p( self.path, :verbose => self.verbose)
150
+ mkdir_p( File.join(self.path, self.public_dir), :verbose => self.verbose)
151
+ mkdir_p( File.join(self.path, self.images_path), :verbose => self.verbose)
152
+ mkdir_p( File.join(self.path, "tmp"), :verbose => self.verbose)
153
+ mkdir_p( File.join(self.path, self.js_path), :verbose => self.verbose)
154
+ mkdir_p( File.join(self.path, self.css_path), :verbose => self.verbose)
155
+ mkdir_p( File.join(self.path, "config"), :verbose => self.verbose) if self.needs_config_folder?
156
+ mkdir_p( File.join(self.path, "coffeescripts"), :verbose => self.verbose) if self.coffeescript
157
+ mkdir_p( File.join(self.path, "sass"), :verbose => self.verbose) if self.sass
151
158
  end
152
159
 
153
160
  # Loop through the libraries the user added
154
161
  # and run their generate methods
155
162
  # which pulls in the additional optional files.
156
163
  def get_libraries
157
- libs.each do |lib|
164
+ self.sorted_libs.each do |lib|
158
165
  library = QEDProject::Libraries::Base.libs[lib]
159
166
  l = library.new(self)
160
167
  l.generate!
@@ -173,8 +180,8 @@ module QEDProject
173
180
 
174
181
  def create_index
175
182
  @project = self
176
- render_template_to_file "index.html", File.join(self.path, "public", "index.html"), binding
177
- puts "Created #{ File.join(self.path, "public", "index.html")}" if self.verbose
183
+ render_template_to_file "index.html", File.join(self.path, self.public_dir, "index.html"), binding
184
+ puts "Created #{ File.join(self.path, self.public_dir, "index.html")}" if self.verbose
178
185
  end
179
186
 
180
187
  def create_rakefile
@@ -1,3 +1,3 @@
1
1
  module QEDProject
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.8"
3
3
  end
data/lib/qedproject.rb CHANGED
@@ -5,10 +5,14 @@ require "qedproject/libraries/jquery"
5
5
  require "qedproject/libraries/backbone"
6
6
  require "qedproject/libraries/knockout"
7
7
  require "qedproject/libraries/jquerytmpl"
8
+ require "qedproject/libraries/jquerymobile"
8
9
  require "qedproject/libraries/skeleton"
9
10
  require "qedproject/project"
11
+ require "qedproject/plugins"
10
12
 
11
13
  module QEDProject
12
14
  class BadLibraryError < RuntimeError
13
15
  end
14
16
  end
17
+
18
+ QEDProject::Plugins::load_plugins
data/templates/assets.yml CHANGED
@@ -1,11 +1,11 @@
1
1
  stylesheets:
2
- style.css:
2
+ app:
3
3
  <% self.css_assets.each do |lib| -%>
4
4
  - <%=File.join(self.css_path, lib) %>
5
5
  <% end -%>
6
6
 
7
7
  javascripts:
8
- app.js:
8
+ app:
9
9
  <% self.js_assets.each do |lib| -%>
10
10
  - <%=File.join(self.js_path, lib) %>
11
11
  <% end -%>
@@ -0,0 +1,3 @@
1
+ describe "A sample spec", ->
2
+ it "performs addition", ->
3
+ (expect 1+1).toEqual 3
Binary file