ember-big_project 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +18 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +208 -0
  6. data/Rakefile +1 -0
  7. data/ember-big_project.gemspec +25 -0
  8. data/lib/ember/big_project.rb +7 -0
  9. data/lib/ember/big_project/version.rb +5 -0
  10. data/lib/generators/ember_proj/bootstrap_generator.rb +291 -0
  11. data/lib/generators/ember_proj/gem_helper.rb +48 -0
  12. data/lib/generators/ember_proj/templates/app/app_loader.js.coffee +16 -0
  13. data/lib/generators/ember_proj/templates/app/authentication.js.coffee +1 -0
  14. data/lib/generators/ember_proj/templates/app/config.js.coffee +1 -0
  15. data/lib/generators/ember_proj/templates/app/config/app.js.coffee +0 -0
  16. data/lib/generators/ember_proj/templates/app/config/display.js.coffee +0 -0
  17. data/lib/generators/ember_proj/templates/app/config/logging.js.coffee +0 -0
  18. data/lib/generators/ember_proj/templates/app/controllers.js.coffee +3 -0
  19. data/lib/generators/ember_proj/templates/app/helpers.js.coffee +1 -0
  20. data/lib/generators/ember_proj/templates/app/lib.js.coffee +1 -0
  21. data/lib/generators/ember_proj/templates/app/mixins.js.coffee +1 -0
  22. data/lib/generators/ember_proj/templates/app/models.js.coffee +3 -0
  23. data/lib/generators/ember_proj/templates/app/routes.js.coffee +4 -0
  24. data/lib/generators/ember_proj/templates/app/state_managers.js.coffee +1 -0
  25. data/lib/generators/ember_proj/templates/app/stores.js.coffee +1 -0
  26. data/lib/generators/ember_proj/templates/app/templates.js.coffee +1 -0
  27. data/lib/generators/ember_proj/templates/app/views.js.coffee +3 -0
  28. data/lib/generators/ember_proj/templates/application.js.coffee +20 -0
  29. data/vendor/assets/javascripts/ember-data-validations.js +68 -0
  30. data/vendor/assets/javascripts/ember-easyForm.js +290 -0
  31. data/vendor/assets/javascripts/ember-formBuilder.js +32 -0
  32. data/vendor/assets/javascripts/ember-validations.js +581 -0
  33. metadata +118 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4dbe5da8f8775543a80386bb8ecc591284cd0d73
4
+ data.tar.gz: f8599b292f35ec98bf093249f0066c0b9d9fad9a
5
+ SHA512:
6
+ metadata.gz: 4980b42384541d6175c8635d54cefacb82d3bf56243802580d0d7c7505581be5a3cb4d3f8bca84a71228ef9b93a2357d0f4acfea20a55438040db808967505aa
7
+ data.tar.gz: 028698a4654fb6bf7abd0816615470da20417033e93a8ea14f551a56bce6e2f3168fcf9de7435203d4e725ccc9a5b1897c259d8f292a5b11c28787788419f17a
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ember-big_project.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Kristian Mandrup
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,208 @@
1
+ # Ember BigProject
2
+
3
+ Create a sensible and extensible Ember project structure for big projects ;)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'ember-big_project'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install ember-big_project
18
+
19
+ ## Usage
20
+
21
+ *Important!!*
22
+
23
+ This bootstrap generators expects that you have set up your Ember project using `ember:bootstrap` or similar generator. Before you execute `ember_proj:bootstrap`, please make sure you have comitted you project to version control, so you go revert in case you need to.
24
+
25
+ Command:
26
+
27
+ $ rails g ember_proj:bootstrap
28
+
29
+ Help!? (see list of options available):
30
+
31
+ $ rails g ember_proj:bootstrap --help
32
+
33
+ Example: add ember-auth basic authentication and emblem templating ;)
34
+
35
+ $ rails g ember_proj:bootstrap --auth ember-auth --emblem
36
+
37
+ ## Ember app structure
38
+
39
+ Proposed (recommended) app structure for large Ember app.
40
+
41
+ ```
42
+ - application.js
43
+
44
+ + app
45
+ - app_loader.js
46
+ + authentication
47
+ + mixins
48
+
49
+ + config
50
+ + locales
51
+ - app.js
52
+ - locale.js
53
+ - logging.js
54
+ - display.js
55
+
56
+ + controllers
57
+ + _mixins
58
+ + users
59
+ - user_controller
60
+ - users_controller
61
+ - session_controller
62
+
63
+ + helpers
64
+ + lib
65
+ + mixins
66
+
67
+ + models
68
+ + extensions
69
+ + mixins
70
+ - user.js
71
+
72
+ + views
73
+ + extensions
74
+ + mixins
75
+ - new_user_view.js
76
+ - user_view.js
77
+ - users_view.js
78
+
79
+ + routes
80
+ + helpers
81
+ + mixins
82
+ + shortcuts
83
+ - user_router.js
84
+ - index_router.js
85
+
86
+ + state_managers
87
+ + templates
88
+ - authentication.js
89
+ - config.js
90
+ - controllers.js
91
+ - helpers.js
92
+ - lib.js
93
+ - mixins.js
94
+ - models.js
95
+ - views.js
96
+ - routes.js
97
+ - state_managers.js
98
+ - templates.js
99
+ ```
100
+
101
+ ## application.js
102
+
103
+ ```
104
+ # application.js
105
+
106
+ #= require modernizr
107
+ #= require jquery
108
+ #= require handlebars
109
+ #= require ruby
110
+ #= require ember
111
+ #= require ember-data
112
+ #= require ember-data-validations
113
+ #= require ember-formBuilder
114
+ #= require bootstrap
115
+
116
+ #= require app/app_loader
117
+
118
+ #= require rails.validations
119
+ #= require rails.validations.ember
120
+
121
+ window.App = Ember.Application.create LOG_TRANSITIONS: true
122
+
123
+ # Defer App readiness until it should be advanced for either
124
+ # testing or production.
125
+ App.deferReadiness()
126
+
127
+ ```
128
+
129
+ ## app/app_loader_.js
130
+
131
+ Responsible for loading all the Ember app files
132
+
133
+ ```javascript
134
+ # app/app_loader_.js
135
+
136
+ #= require_self
137
+
138
+ #= require_tree lib
139
+ #= require_tree mixins
140
+ #= require_tree helpers
141
+ #= require_tree config
142
+
143
+ #= require store
144
+ #= require models
145
+ #= require controllers
146
+ #= require views
147
+
148
+ #= require state_managers
149
+ #= require authentication
150
+ #= require routes
151
+
152
+ ```
153
+
154
+ ## models.js
155
+
156
+ Index files such as 'models.js' are useful in order to quickly change the load order of files or add/remove files to be included in the app ;)
157
+
158
+ You will likley have specific mixins for models, that should be loaded before the models they are mixed into - the reason for this pattern.
159
+
160
+ You can then make custom extensions to your models, after they have applied whatever mixins they need or directly extend built-in Ember classes ;)
161
+
162
+ ```javascript
163
+ # models.js
164
+ #= require_tree models/mixins
165
+ #= require_tree models
166
+ #= require_tree models/extensions
167
+ ```
168
+
169
+ And so on ...
170
+
171
+ ## Vendor libs included
172
+
173
+ These vendor libs can be required directly in your `application.js.coffee`.
174
+
175
+ Alternatively create a `vendor.js.coffee` which you require from `application.js.coffee`.
176
+
177
+ Note: Some vendor libs will need to be required after `require app/app_loader`, if they hook into the Application classes you have defined (f.ex `rails.validations.ember` lib).
178
+
179
+ * [ember-formbuilder](https://github.com/luan/ember-formbuilder)
180
+ * [ember-easyForm](https://github.com/dockyard/ember-easyForm)
181
+ * [ember-validations](https://github.com/dockyard/ember-validations)
182
+ * [ember-data-validations](https://github.com/Myslik/ember-data-validations)
183
+
184
+ See also: [formBuilder](http://luansantos.com/2012/03/19/introducing-ember-formbuilder/)
185
+
186
+ Distros:
187
+
188
+ * [validations](https://github.com/dockyard/ember-builds/tree/master/validations)
189
+ * [easyForm](https://github.com/dockyard/ember-builds/tree/master/easyForm)
190
+
191
+
192
+ If you find one or more of these vendor libs are outdated, please make a patch with the updated lib and send me a pull request! Thanks :)
193
+
194
+ ## Test setup
195
+
196
+ For easy test setup of your project, try using the [ember-konacha-rails](https://github.com/kristianmandrup/ember-konacha-rails) gem ;)
197
+
198
+ TODO: In the future Test setup is likely to be integrated directly in this gem!
199
+
200
+ Also look at [ember-tools](https://github.com/rpflorence/ember-tools) for more tooling!!
201
+
202
+ ## Contributing
203
+
204
+ 1. Fork it
205
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
206
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
207
+ 4. Push to the branch (`git push origin my-new-feature`)
208
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ember/big_project/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ember-big_project"
8
+ spec.version = Ember::BigProject::VERSION
9
+ spec.authors = ["Kristian Mandrup"]
10
+ spec.email = ["kmandrup@gmail.com"]
11
+ spec.description = %q{Configure Rails assets structure for a big Ember project}
12
+ spec.summary = %q{Creates a more refined Ember project structure}
13
+ spec.homepage = "https://github.com/kristianmandrup/ember-big_project"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "rails", ">= 3.1"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ end
@@ -0,0 +1,7 @@
1
+ require "ember/big_project/version"
2
+
3
+ module Ember
4
+ module BigProject
5
+ # Your code goes here...
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ module Ember
2
+ module BigProject
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,291 @@
1
+ require 'generators/ember_proj/gem_helper'
2
+ require 'fileutils'
3
+
4
+ module EmberProj
5
+ module Generators
6
+ class BootstrapGenerator < Rails::Generators::Base
7
+ class_option :csv, type: :boolean, default: false,
8
+ desc: 'Add client side validations integration'
9
+
10
+ class_option :emblem, type: :boolean, default: false,
11
+ desc: 'Use Emblem templates (like slim)'
12
+
13
+ class_option :auth, type: :array, default: [],
14
+ desc: 'Authentication libraries to use (oauth2, auth)'
15
+
16
+ class_option :bundle, type: :boolean, default: false,
17
+ desc: 'Do not bundle gems unless absolutely required!'
18
+
19
+ TPL_PATH = File.expand_path('../templates', __FILE__)
20
+
21
+ source_root TPL_PATH
22
+
23
+ def skeleton
24
+ directory "app", "app/assets/javascripts/app", recursive: true
25
+
26
+ app_directories.each do |app_dir|
27
+ src = "app/#{app_dir}"
28
+ target = "app/assets/javascripts/app/#{app_dir}"
29
+
30
+ directory src, target, recursive: true
31
+
32
+ sub_dirs.each do |sub_dir|
33
+ sub_src = File.join(src, sub_dir)
34
+
35
+ full_sub_path = File.join(TPL_PATH, sub_src)
36
+
37
+ if File.directory? full_sub_path
38
+ sub_target = File.join(target, sub_dir)
39
+ directory sub_src, sub_target, recursive: true
40
+ end
41
+ end
42
+ end
43
+
44
+ copy_file "application.js.coffee", (js_path(application) + '.coffee')
45
+ end
46
+
47
+ def move_ember_files
48
+ say "Moving existing ember files...", :green
49
+ move_to_app 'views/application_view', 'controllers/application_controller'
50
+ move 'store', 'app/stores/store'
51
+ move 'router', 'app/routes/router'
52
+
53
+ # remove default application.js file
54
+ # replaced by coffee version supplied by this gem!
55
+ say "Cleanup...", :green
56
+
57
+ if File.exist? Rails.root.join js_path('.js/.coffee')
58
+ # Somehow I can't seem to get rid of this file!!!
59
+ remove_file js_path('.js/.coffee')
60
+ end
61
+
62
+ if File.exist? Rails.root.join js_path('.js/.coffee')
63
+ # remove old application.js manifest
64
+ remove_file js_path('application')
65
+ end
66
+ end
67
+
68
+ def authentications
69
+ return if auth.blank?
70
+
71
+ validate_auth!
72
+ use_auth_gems.each do |name|
73
+ auth_notice name
74
+
75
+ gem name unless has_gem? name
76
+ end
77
+ end
78
+
79
+ def emblem
80
+ return unless emblem?
81
+ gem 'emblem-rails' unless has_gem? 'emblem-rails'
82
+
83
+ say "Note: Emblem templates have the form: my_template.js.emblem", :green
84
+ end
85
+
86
+ def client_side_validations
87
+ return unless csv?
88
+ gem 'client_side_validations' unless has_gem? 'client_side_validations'
89
+ gem 'client_side_validations-ember' unless has_gem? 'client_side_validations-ember'
90
+ end
91
+
92
+ def bundle_all
93
+ if csv?
94
+ bundle_gems!
95
+ invoke "client_side_validations:ember:install"
96
+ else
97
+ bundle_gems! if bundle?
98
+ end
99
+ end
100
+
101
+ def notices
102
+ draw_border :thick
103
+ auth_notices!
104
+ extras_notice!
105
+ other_gems_notice!
106
+ end
107
+
108
+ protected
109
+
110
+ include EmberProj::GemHelper
111
+
112
+ def sub_dirs
113
+ %w{locales mixins extensions shortcuts}
114
+ end
115
+
116
+ def bundle?
117
+ options[:bundle]
118
+ end
119
+
120
+ # TODO: allow customization - which to include/exclude!
121
+ def app_directories
122
+ %w{authentication config controllers helpers lib mixins models routes state_managers stores templates views}
123
+ end
124
+
125
+ attr_reader :auth_notices
126
+
127
+ def auth_notices!
128
+ if auth_notices.empty?
129
+ say "Authentication: was not configured", :green
130
+ return
131
+ end
132
+
133
+ say "Authentication:", :green
134
+ say auth_notices.join("\n"), :green
135
+ say ""
136
+ end
137
+
138
+ def auth_notices
139
+ @auth_notices ||= []
140
+ end
141
+
142
+ def auth_notice name
143
+ auth_notices << "See: #{auth_repo name} for authentication configuration details"
144
+ end
145
+
146
+ def auth_repo name
147
+ case name.to_s
148
+ when 'ember-auth-rails'
149
+ 'https://github.com/heartsentwined/ember-auth-rails'
150
+ when 'ember-oauth2-rails'
151
+ 'https://github.com/amkirwan/ember-oauth2'
152
+ else
153
+ say "Invalid auth gem: #{name}, must be oauth2 or auth", :red
154
+ exit
155
+ end
156
+ end
157
+
158
+ def validate_auth!
159
+ return if options[:auth].blank?
160
+
161
+ if use_auth_gems.empty?
162
+ say "Not a supported authentication gem: #{auth}. Must be one of #{auth_gems}", :red
163
+ end
164
+ end
165
+
166
+ def use_auth_gems
167
+ [auth].flatten & auth_gems
168
+ end
169
+
170
+ def auth
171
+ @auth ||= options[:auth].map do |name|
172
+ case name
173
+ when 'oauth', 'oauth2', 'ember-oauth', 'ember-oauth2'
174
+ 'ember-oauth2-rails'
175
+ when 'auth', 'ember-auth'
176
+ 'ember-auth-rails'
177
+ else
178
+ name
179
+ end
180
+ end
181
+ end
182
+
183
+ def auth_gems
184
+ %w{ember-auth-rails ember-oauth2-rails}
185
+ end
186
+
187
+ def move_to_app *paths
188
+ paths.flatten.each do |path|
189
+ move_it! js_path(path), js_app_path(path)
190
+ end
191
+ end
192
+
193
+ def move src, target
194
+ src = js_path(src)
195
+ target = js_path(target)
196
+
197
+ move_it! src, target
198
+ end
199
+
200
+ def move_it! src, target
201
+ return unless File.exist? src
202
+
203
+ say_status :move, "#{src} -> #{target}"
204
+
205
+ FileUtils.mv src, target
206
+ end
207
+
208
+ def strip_front path
209
+ "app/assets" + path.to_s.split(/app\/assets/)[1]
210
+ end
211
+
212
+ def js_app_path path
213
+ js_path File.join('app', path)
214
+ end
215
+
216
+ def js_path path
217
+ path = "#{path}.js" unless path =~ /\.js$/
218
+ Rails.root.join('app/assets/javascripts', path)
219
+ end
220
+
221
+ def emblem?
222
+ options[:emblem]
223
+ end
224
+
225
+ def csv?
226
+ options[:csv]
227
+ end
228
+
229
+ def extras_notice!
230
+ draw_border
231
+ say extras_notice, :green
232
+ end
233
+
234
+ def extras_notice
235
+ %Q{The following extra libs are referenced in this setup:
236
+
237
+ #{join extras}
238
+
239
+ Include these libs, using respective gems (#{join gems_list}) or the equivalent js files.
240
+
241
+ Note: You can also remove the libs you don't need from the application.js.coffee manifest
242
+ }
243
+ end
244
+
245
+ def draw_border type = :thin
246
+ say border(type), :green
247
+ end
248
+
249
+ def nice text
250
+ border + text
251
+ end
252
+
253
+ def border type = :thin
254
+ border_char(type) * border_width + "\n"
255
+ end
256
+
257
+ def border_char type
258
+ type == :thick ? "=" : '-'
259
+ end
260
+
261
+ def border_width
262
+ 80
263
+ end
264
+
265
+ def join list
266
+ list.join ', '
267
+ end
268
+
269
+ def other_gems_notice!
270
+ draw_border
271
+ say other_gems_notice, :green
272
+ end
273
+
274
+ def other_gems_notice
275
+ "Other useful gems: #{other_gems}\n"
276
+ end
277
+
278
+ def other_gems
279
+ %q{ember-i18n-rails ember-auth-rails ember-oauth2-rails ember-bootstrap-rails}
280
+ end
281
+
282
+ def extras
283
+ %w{ember-data ember-data-validations ember-formBuilder ember-easyForm bootstrap rails.validations.ember}
284
+ end
285
+
286
+ def gems_list
287
+ %w{client_side_validations-ember bootstrap-sass ember-rails}
288
+ end
289
+ end
290
+ end
291
+ end