joosy 1.1.2 → 1.2.0.alpha.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +6 -7
  3. data/Gemfile +1 -11
  4. data/Gruntfile.coffee +138 -0
  5. data/README.md +65 -24
  6. data/bin/joosy +21 -0
  7. data/bower.json +23 -0
  8. data/joosy.gemspec +6 -12
  9. data/lib/joosy.js +3754 -0
  10. data/lib/joosy.rb +8 -9
  11. data/package.json +37 -0
  12. data/spec/{javascripts/helpers/spec_helper.js.coffee → helpers/helper.coffee} +0 -0
  13. data/spec/{javascripts/joosy/core/application_spec.js.coffee → joosy/core/application_spec.coffee} +0 -0
  14. data/spec/{javascripts/joosy/core/form_spec.js.coffee → joosy/core/form_spec.coffee} +30 -30
  15. data/spec/{javascripts/joosy/core/helpers/forms_spec.js.coffee → joosy/core/helpers/forms_spec.coffee} +0 -0
  16. data/spec/{javascripts/joosy/core/helpers/view_spec.js.coffee → joosy/core/helpers/view_spec.coffee} +0 -0
  17. data/spec/{javascripts/joosy/core/helpers/widgets_spec.js.coffee → joosy/core/helpers/widgets_spec.coffee} +0 -0
  18. data/spec/{javascripts/joosy/core/joosy_spec.js.coffee → joosy/core/joosy_spec.coffee} +0 -0
  19. data/spec/{javascripts/joosy/core/layout_spec.js.coffee → joosy/core/layout_spec.coffee} +0 -0
  20. data/spec/{javascripts/joosy/core/modules/container_spec.js.coffee → joosy/core/modules/container_spec.coffee} +1 -1
  21. data/spec/{javascripts/joosy/core/modules/events_spec.js.coffee → joosy/core/modules/events_spec.coffee} +0 -0
  22. data/spec/{javascripts/joosy/core/modules/filters_spec.js.coffee → joosy/core/modules/filters_spec.coffee} +0 -0
  23. data/spec/{javascripts/joosy/core/modules/log_spec.js.coffee → joosy/core/modules/log_spec.coffee} +0 -0
  24. data/spec/{javascripts/joosy/core/modules/module_spec.js.coffee → joosy/core/modules/module_spec.coffee} +0 -0
  25. data/spec/{javascripts/joosy/core/modules/renderer_spec.js.coffee → joosy/core/modules/renderer_spec.coffee} +35 -0
  26. data/spec/{javascripts/joosy/core/modules/time_manager_spec.js.coffee → joosy/core/modules/time_manager_spec.coffee} +0 -0
  27. data/spec/{javascripts/joosy/core/modules/widget_manager_spec.js.coffee → joosy/core/modules/widget_manager_spec.coffee} +0 -0
  28. data/spec/{javascripts/joosy/core/page_spec.js.coffee → joosy/core/page_spec.coffee} +0 -0
  29. data/spec/{javascripts/joosy/core/resource/collection_spec.js.coffee → joosy/core/resource/collection_spec.coffee} +0 -0
  30. data/spec/{javascripts/joosy/core/resource/generic_spec.js.coffee → joosy/core/resource/generic_spec.coffee} +0 -0
  31. data/spec/{javascripts/joosy/core/resource/rest_collection_spec.js.coffee → joosy/core/resource/rest_collection_spec.coffee} +0 -0
  32. data/spec/{javascripts/joosy/core/resource/rest_spec.js.coffee → joosy/core/resource/rest_spec.coffee} +0 -8
  33. data/spec/{javascripts/joosy/core/router_spec.js.coffee → joosy/core/router_spec.coffee} +19 -22
  34. data/spec/{javascripts/joosy/core/templaters/rails_jst_spec.js.coffee → joosy/core/templaters/rails_jst_spec.coffee} +0 -0
  35. data/spec/{javascripts/joosy/core/widget_spec.js.coffee → joosy/core/widget_spec.coffee} +0 -0
  36. data/spec/{javascripts/joosy/preloaders/caching_spec.js.coffee → joosy/preloaders/caching_spec.coffee} +2 -2
  37. data/spec/{javascripts/joosy/preloaders/inline_spec.js.coffee → joosy/preloaders/inline_spec.coffee} +1 -1
  38. data/spec/support/test.js +1 -0
  39. data/{app/assets/javascripts/joosy/core/application.js.coffee → src/joosy/core/application.coffee} +0 -0
  40. data/{app/assets/javascripts/joosy/core/form.js.coffee → src/joosy/core/form.coffee} +5 -5
  41. data/{app/assets/javascripts/joosy/core/helpers/form.js.coffee → src/joosy/core/helpers/form.coffee} +0 -0
  42. data/{app/assets/javascripts/joosy/core/helpers/view.js.coffee → src/joosy/core/helpers/view.coffee} +0 -0
  43. data/{app/assets/javascripts/joosy/core/helpers/widgets.js.coffee → src/joosy/core/helpers/widgets.coffee} +0 -0
  44. data/{app/assets/javascripts/joosy/core/joosy.js.coffee → src/joosy/core/joosy.coffee} +1 -1
  45. data/{app/assets/javascripts/joosy/core/layout.js.coffee → src/joosy/core/layout.coffee} +0 -0
  46. data/{app/assets/javascripts/joosy/core/modules/container.js.coffee → src/joosy/core/modules/container.coffee} +1 -1
  47. data/{app/assets/javascripts/joosy/core/modules/events.js.coffee → src/joosy/core/modules/events.coffee} +4 -6
  48. data/{app/assets/javascripts/joosy/core/modules/filters.js.coffee → src/joosy/core/modules/filters.coffee} +0 -0
  49. data/{app/assets/javascripts/joosy/core/modules/log.js.coffee → src/joosy/core/modules/log.coffee} +0 -0
  50. data/{app/assets/javascripts/joosy/core/modules/module.js.coffee → src/joosy/core/modules/module.coffee} +0 -0
  51. data/{app/assets/javascripts/joosy/core/modules/renderer.js.coffee → src/joosy/core/modules/renderer.coffee} +1 -1
  52. data/{app/assets/javascripts/joosy/core/modules/time_manager.js.coffee → src/joosy/core/modules/time_manager.coffee} +0 -0
  53. data/{app/assets/javascripts/joosy/core/modules/widgets_manager.js.coffee → src/joosy/core/modules/widgets_manager.coffee} +0 -0
  54. data/{app/assets/javascripts/joosy/core/page.js.coffee → src/joosy/core/page.coffee} +0 -1
  55. data/{app/assets/javascripts/joosy/core/preloader.js.coffee → src/joosy/core/preloader.coffee} +0 -0
  56. data/{app/assets/javascripts/joosy/core/resource/collection.js.coffee → src/joosy/core/resource/collection.coffee} +0 -0
  57. data/{app/assets/javascripts/joosy/core/resource/generic.js.coffee → src/joosy/core/resource/generic.coffee} +5 -5
  58. data/{app/assets/javascripts/joosy/core/resource/rest.js.coffee → src/joosy/core/resource/rest.coffee} +5 -5
  59. data/{app/assets/javascripts/joosy/core/resource/rest_collection.js.coffee → src/joosy/core/resource/rest_collection.coffee} +0 -0
  60. data/src/joosy/core/resource/watcher.coffee +50 -0
  61. data/{app/assets/javascripts/joosy/core/router.js.coffee → src/joosy/core/router.coffee} +28 -30
  62. data/{app/assets/javascripts/joosy/core/templaters/rails_jst.js.coffee → src/joosy/core/templaters/rails_jst.coffee} +12 -2
  63. data/{app/assets/javascripts/joosy/core/widget.js.coffee → src/joosy/core/widget.coffee} +0 -0
  64. data/src/joosy/generators/command.coffee +49 -0
  65. data/src/joosy/generators/generator.coffee +93 -0
  66. data/src/joosy/generators/layout.coffee +20 -0
  67. data/src/joosy/generators/page.coffee +20 -0
  68. data/src/joosy/generators/project/base.coffee +28 -0
  69. data/src/joosy/generators/project/standalone.coffee +25 -0
  70. data/src/joosy/generators/project.coffee +16 -0
  71. data/src/joosy/generators/widget.coffee +20 -0
  72. data/{app/assets/javascripts/joosy/preloaders/caching.js.coffee → src/joosy/preloaders/caching.coffee} +0 -0
  73. data/{app/assets/javascripts/joosy/preloaders/inline.js.coffee → src/joosy/preloaders/inline.coffee} +0 -0
  74. data/src/joosy.coffee +2 -0
  75. data/src/vendor/metamorph.coffee +410 -0
  76. data/tasks/joosy.coffee +63 -0
  77. data/templates/application/base/application.coffee +11 -0
  78. data/{lib/rails/generators/joosy/templates/app/helpers/application.js.coffee → templates/application/base/helpers/application.coffee} +0 -0
  79. data/{lib/rails/generators/joosy/templates/app/layouts/application.js.coffee → templates/application/base/layouts/application.coffee} +0 -0
  80. data/{lib/rails/generators/joosy/templates/app/pages/application.js.coffee → templates/application/base/pages/application.coffee} +0 -0
  81. data/{lib/rails/generators/joosy/templates/app/pages/welcome/index.js.coffee → templates/application/base/pages/welcome/index.coffee} +3 -3
  82. data/templates/application/base/routes.coffee +3 -0
  83. data/{lib/rails/generators/joosy/templates/app → templates/application/base}/templates/layouts/application.jst.hamlc +0 -0
  84. data/{lib/rails/generators/joosy/templates/app → templates/application/base}/templates/pages/welcome/index.jst.hamlc +1 -2
  85. data/templates/application/standalone/.gitignore +5 -0
  86. data/templates/application/standalone/Gruntfile.coffee +40 -0
  87. data/templates/application/standalone/Procfile +1 -0
  88. data/templates/application/standalone/bower.json +7 -0
  89. data/templates/application/standalone/package.json +24 -0
  90. data/templates/application/standalone/source/index.haml +7 -0
  91. data/templates/application/standalone/stylesheets/application.styl +2 -0
  92. data/templates/layout/basic.coffee +2 -0
  93. data/templates/layout/namespaced.coffee +4 -0
  94. data/templates/page/basic.coffee +3 -0
  95. data/templates/page/namespaced.coffee +5 -0
  96. data/templates/widget/basic.coffee +2 -0
  97. data/templates/widget/namespaced.coffee +4 -0
  98. metadata +98 -179
  99. data/.codoopts +0 -5
  100. data/Gemfile.lock +0 -157
  101. data/Guardfile +0 -32
  102. data/LICENSE +0 -22
  103. data/MIT-LICENSE +0 -21
  104. data/Rakefile +0 -14
  105. data/app/assets/javascripts/joosy.js.coffee +0 -5
  106. data/app/helpers/joosy/sprockets_helper.rb +0 -41
  107. data/app/views/layouts/json_wrapper.json.erb +0 -1
  108. data/lib/joosy/rails/engine.rb +0 -24
  109. data/lib/joosy/version.rb +0 -3
  110. data/lib/rails/generators/joosy/application_generator.rb +0 -43
  111. data/lib/rails/generators/joosy/joosy_base.rb +0 -30
  112. data/lib/rails/generators/joosy/layout_generator.rb +0 -30
  113. data/lib/rails/generators/joosy/page_generator.rb +0 -42
  114. data/lib/rails/generators/joosy/preloader_generator.rb +0 -30
  115. data/lib/rails/generators/joosy/resource_generator.rb +0 -40
  116. data/lib/rails/generators/joosy/templates/app/layouts/template.js.coffee +0 -2
  117. data/lib/rails/generators/joosy/templates/app/pages/template.js.coffee +0 -5
  118. data/lib/rails/generators/joosy/templates/app/resources/template.js.coffee +0 -2
  119. data/lib/rails/generators/joosy/templates/app/resources/template_with_namespace.js.coffee +0 -4
  120. data/lib/rails/generators/joosy/templates/app/routes.js.coffee +0 -8
  121. data/lib/rails/generators/joosy/templates/app/widgets/template.js.coffee +0 -2
  122. data/lib/rails/generators/joosy/templates/app.js.coffee +0 -11
  123. data/lib/rails/generators/joosy/templates/app_controller.rb +0 -9
  124. data/lib/rails/generators/joosy/templates/app_preloader.js.coffee.erb +0 -13
  125. data/lib/rails/generators/joosy/templates/app_railties.js.coffee.erb +0 -11
  126. data/lib/rails/generators/joosy/templates/preload.html.erb +0 -26
  127. data/lib/rails/generators/joosy/templates/preload.html.haml +0 -19
  128. data/lib/rails/generators/joosy/templates/preload.html.slim +0 -19
  129. data/lib/rails/generators/joosy/widget_generator.rb +0 -30
  130. data/lib/rails/resources_with_joosy.rb +0 -11
  131. data/spec/javascripts/support/assets/coolface.jpg +0 -0
  132. data/spec/javascripts/support/assets/okay.jpg +0 -0
  133. data/spec/javascripts/support/assets/test.js +0 -1
  134. data/spec/javascripts/support/jasmine.yml +0 -74
  135. data/spec/javascripts/support/jasmine_config.rb +0 -23
  136. data/spec/javascripts/support/jasmine_runner.rb +0 -32
  137. data/spec/javascripts/support/sinon-1.3.1.js +0 -3469
  138. data/spec/javascripts/support/sinon-ie-1.3.1.js.skip +0 -82
  139. data/vendor/assets/javascripts/jquery.form.js +0 -1190
  140. data/vendor/assets/javascripts/jquery.hashchange.js +0 -390
  141. data/vendor/assets/javascripts/metamorph.js +0 -409
  142. data/vendor/assets/javascripts/sugar.js +0 -8637
@@ -69,15 +69,15 @@ class Joosy.Resource.Generic extends Joosy.Module
69
69
  #
70
70
  # @private
71
71
  #
72
- class clone extends this
72
+ class Clone extends this
73
73
 
74
74
  if entity instanceof Joosy.Resource.Generic
75
- clone.__source = entity.memberPath()
76
- clone.__source += '/' + @::__entityName.pluralize() if @::__entityName
75
+ Clone.__source = entity.memberPath()
76
+ Clone.__source += '/' + @::__entityName.pluralize() if @::__entityName
77
77
  else
78
- clone.__source = entity
78
+ Clone.__source = entity
79
79
 
80
- clone
80
+ Clone
81
81
 
82
82
  #
83
83
  # Sets the entity text name:
@@ -36,11 +36,11 @@ class Joosy.Resource.REST extends Joosy.Resource.Generic
36
36
  # Resource.basePath() # /resources
37
37
  #
38
38
  @basePath: (options={}) ->
39
- if @__source
39
+ if @__source? && !options.parent?
40
40
  path = @__source
41
41
  else
42
42
  path = '/'
43
- path += @__namespace__.map((s)-> s.underscore()).join('/') + '/' if @__namespace__.length > 0
43
+ path += @__namespace__.map((s)-> s.toLowerCase()).join('/') + '/' if @__namespace__.length > 0
44
44
  path += @::__entityName.pluralize()
45
45
 
46
46
  if options.parent?
@@ -53,7 +53,7 @@ class Joosy.Resource.REST extends Joosy.Resource.Generic
53
53
  #
54
54
  # @see Joosy.Resource.REST.basePath
55
55
  #
56
- basePath: (options) ->
56
+ basePath: (options={}) ->
57
57
  @constructor.basePath options
58
58
 
59
59
  #
@@ -78,7 +78,7 @@ class Joosy.Resource.REST extends Joosy.Resource.Generic
78
78
  # @example Basic usage
79
79
  # resource.memberPath(from: 'foo') # /resources/1/foo
80
80
  #
81
- memberPath: (options) ->
81
+ memberPath: (options={}) ->
82
82
  @constructor.memberPath @id(), options
83
83
 
84
84
  #
@@ -99,7 +99,7 @@ class Joosy.Resource.REST extends Joosy.Resource.Generic
99
99
  #
100
100
  # @see Joosy.Resource.REST.collectionPath
101
101
  #
102
- collectionPath: (options) ->
102
+ collectionPath: (options={}) ->
103
103
  @constructor.collectionPath options
104
104
 
105
105
  #
@@ -0,0 +1,50 @@
1
+ class Joosy.Resource.Watcher extends Joosy.Module
2
+ @include Joosy.Modules.Events
3
+
4
+ @cache: (cacheKey) -> @::__cacheKey = cacheKey
5
+ @fetcher: (fetcher) -> @::__fetcher = fetcher
6
+
7
+ @beforeLoad: (action) ->
8
+ unless @::hasOwnProperty '__beforeLoads'
9
+ @::__beforeLoads = [].concat @.__super__.__beforeLoads || []
10
+ @::__beforeLoads.push action
11
+
12
+ constructor: (cacheKey=false, fetcher=false) ->
13
+ if Object.isFunction(cacheKey)
14
+ fetcher = cacheKey
15
+ cacheKey = undefined
16
+
17
+ @__fetcher = fetcher if fetcher
18
+ @__cacheKey = cacheKey if cacheKey
19
+
20
+ load: (callback) ->
21
+ if @__cacheKey && localStorage[@__cacheKey]
22
+ @data = @prepare(JSON.parse localStorage[@__cacheKey])
23
+ @trigger 'changed'
24
+ @refresh()
25
+ callback? @
26
+ else
27
+ @__fetcher (result) =>
28
+ localStorage[@__cacheKey] = JSON.stringify(result) if @__cacheKey
29
+ @data = @prepare result
30
+ @trigger 'changed'
31
+ callback? @
32
+
33
+ clone: ->
34
+ copy = new @constructor(@__cacheKey, @__fetcher)
35
+ copy.data = Object.clone(@data, true)
36
+ copy.trigger 'changed'
37
+ copy
38
+
39
+ refresh: (callback) ->
40
+ @__fetcher (result) =>
41
+ localStorage[@__cacheKey] = JSON.stringify(result) if @__cacheKey
42
+ @data = @prepare result
43
+ @trigger 'changed'
44
+ callback? @
45
+
46
+ prepare: (data) ->
47
+ if @__beforeLoads?
48
+ data = bl.call(this, data) for bl in @__beforeLoads
49
+
50
+ data
@@ -26,19 +26,19 @@ Joosy.Router =
26
26
  # need) and actual executors
27
27
  #
28
28
  routes: Object.extended()
29
-
29
+
30
30
  #
31
31
  # The regexp to restrict the next loading url. By default set to false and
32
32
  # therefore no restrictions apply.
33
33
  #
34
34
  restrictPattern: false
35
-
35
+
36
36
  #
37
37
  # TODO: Write readme
38
38
  #
39
39
  __namespace: ""
40
40
  __asNamespace: ""
41
-
41
+
42
42
  #
43
43
  # Set the restriction pattern. If the requested url does not match this it
44
44
  # will not load. Set `false` to avoid check.
@@ -53,8 +53,8 @@ Joosy.Router =
53
53
  @routes = Object.extended()
54
54
  @__namespace = ""
55
55
  @__asNamespace = ""
56
-
57
-
56
+
57
+
58
58
  #
59
59
  # Draws the routes similar to Ruby on Rails
60
60
  #
@@ -95,9 +95,9 @@ Joosy.Router =
95
95
  , 2 # jQuery.hashchange checks hash changing every 1ms
96
96
  else
97
97
  history[if options.replaceState then 'replaceState' else 'pushState'] {}, '', '#'+path
98
-
98
+
99
99
  #
100
- # Match route (adds it to @rawRoutes)
100
+ # Match route (ads it to @rawRoutes)
101
101
  #
102
102
  # @param [String] route similar to ones sent in map hash
103
103
  #
@@ -106,19 +106,19 @@ Joosy.Router =
106
106
  #
107
107
  match: (route, options={}) ->
108
108
  if @__asNamespace
109
- as = @__asNamespace + options.as.capitalize()
109
+ as = @__asNamespace + options["as"].capitalize()
110
110
  else
111
- as = options.as
112
-
111
+ as = options["as"]
112
+
113
113
  routeName = @__namespace + route
114
114
 
115
115
  map = {}
116
- map[route] = options.to
117
-
116
+ map[route] = options["to"]
117
+
118
118
  Joosy.Module.merge @rawRoutes, map
119
-
119
+
120
120
  @__injectReverseUrl(as, routeName)
121
-
121
+
122
122
  #
123
123
  # Shortcut to match "/"
124
124
  #
@@ -127,17 +127,17 @@ Joosy.Router =
127
127
  # default it is "root"
128
128
  #
129
129
  root: (options={}) ->
130
- as = options.as || "root"
131
- @match("/", to: options.to, as: as)
132
-
130
+ as = options["as"] || "root"
131
+ @match("/", to: options["to"], as: as)
132
+
133
133
  #
134
134
  # Routes the 404
135
135
  #
136
136
  # @param options [String] to function to which the route routes
137
137
  #
138
138
  notFound: (options={}) ->
139
- @match(404, to: options.to)
140
-
139
+ @match(404, to: options["to"])
140
+
141
141
  #
142
142
  # Namespaces a match route
143
143
  #
@@ -149,23 +149,21 @@ Joosy.Router =
149
149
  if Object.isFunction(options)
150
150
  block = options
151
151
  options = {}
152
-
152
+
153
153
  newScope = $.extend({}, this)
154
154
  newScope.rawRoutes = {}
155
155
  newScope.__namespace += name
156
- if options.as
157
- options.as = options.as.capitalize() if newScope.__asNamespace.length > 0
158
- newScope.__asNamespace += options.as
156
+ newScope.__asNamespace += "#{options["as"]}" if options["as"]
159
157
  block.call(newScope) if Object.isFunction(block)
160
158
  @rawRoutes[name] = newScope.rawRoutes
161
-
159
+
162
160
  #
163
161
  # Inits the routing system and loads the current route
164
162
  # Binds the window hashchange event and therefore should only be called once
165
163
  # during system startup
166
164
  #
167
165
  __setupRoutes: ->
168
- $(window).hashchange =>
166
+ $(window).on 'hashchange', =>
169
167
  unless @__ignoreRequest && location.hash.match(@__ignoreRequest)
170
168
  @__respondRoute location.hash
171
169
 
@@ -279,11 +277,11 @@ Joosy.Router =
279
277
  params[pair[0]] = pair[1]
280
278
 
281
279
  params
282
-
280
+
283
281
  #
284
282
  # Injects reverse routing function into global namespace
285
283
  # @param [String] as The name for the route, ex: for "projects"
286
- # builds "projectsUrl" and "projectsPath" functions
284
+ # builds "projects_url" and "projects_path" functions
287
285
  # @param [String] route Entire route, joined by namespaces, ex:
288
286
  # "/projects/":
289
287
  # "/:id" :
@@ -292,7 +290,7 @@ Joosy.Router =
292
290
  #
293
291
  __injectReverseUrl: (as, route) ->
294
292
  return if as == undefined
295
-
293
+
296
294
  fnc = (options) ->
297
295
  url = route
298
296
  (route.match(/\/:[^\/]+/g) || []).each (str) ->
@@ -301,9 +299,9 @@ Joosy.Router =
301
299
 
302
300
  Joosy.Helpers.Application["#{as}Path"] = (options) ->
303
301
  fnc(options)
304
-
302
+
305
303
  Joosy.Helpers.Application["#{as}Url"] = (options) ->
306
- url = window.location.protocol + '//' + window.location.host + window.location.pathname
304
+ url = 'http://' + window.location.host + window.location.pathname
307
305
  "#{url}#{fnc(options)}"
308
306
 
309
307
  Joosy.Module.merge Joosy.Router, Joosy.Modules.Events
@@ -12,8 +12,18 @@ class Joosy.Templaters.RailsJST
12
12
  # @param [String] name Template name 'foo/bar'
13
13
  #
14
14
  buildView: (name) ->
15
- unless template = JST[location = "#{@applicationName}/templates/#{name}-#{I18n?.locale}"]
16
- template = JST[location = "#{@applicationName}/templates/#{name}"]
15
+ template = false
16
+ haystack = [
17
+ "#{@applicationName}/templates/#{name}-#{I18n?.locale}",
18
+ "#{@applicationName}/templates/#{name}",
19
+ "templates/#{name}-#{I18n?.locale}",
20
+ "templates/#{name}"
21
+ ]
22
+
23
+ haystack.each (path) ->
24
+ if JST[path]
25
+ location = path
26
+ template = JST[path]
17
27
 
18
28
  unless template
19
29
  throw new Error "Template '#{name}' not found. Checked at: #{location}"
@@ -0,0 +1,49 @@
1
+ module.exports = ->
2
+ Sugar = require 'sugar'
3
+ cli = require 'command-router'
4
+ meta = require '../../../package.json'
5
+ grunt = require 'grunt'
6
+
7
+ cli.command /new\s?(.*)?/, ->
8
+ name = cli.params.splats[0]
9
+
10
+ unless name?
11
+ console.error "Usage: `new :name`. Run `help` for details."
12
+ process.exit(1)
13
+
14
+ generator = require('./project')
15
+ generator = new generator(name)
16
+ generator.generate()
17
+ generator.perform -> process.exit 0
18
+
19
+ cli.command /g(enerate)?\s?(.*)/, ->
20
+ params = cli.params.splats[1].split(' ')
21
+ entity = params[0]
22
+ name = params[1]
23
+
24
+ generators = ['page', 'resource', 'widget', 'layout']
25
+
26
+ if !entity? || !name?
27
+ console.error "Usage: `generate :entity :name`. Run `help` for details."
28
+ process.exit 1
29
+
30
+ unless generators.some(entity)
31
+ console.error "Don't know how to generate '#{entity}'. Possible values: #{generators.join(', ')}."
32
+ process.exit 1
33
+
34
+ unless grunt.file.exists(process.cwd(), 'source')
35
+ console.error "Failed: `source' directory not found. Are you in the root of project?"
36
+ process.exit 1
37
+
38
+ generator = require("./#{entity}")
39
+ generator = new generator(name)
40
+ generator.generate()
41
+ generator.perform -> process.exit 0
42
+
43
+ cli.on 'notfound', (action) ->
44
+ if action.length > 0
45
+ console.error "'#{action}' is an unknown action :("
46
+ else
47
+ console.log "Joosy #{meta.version}. Run `help` to list possible commands."
48
+
49
+ cli.parse process.argv
@@ -0,0 +1,93 @@
1
+ File = require('grunt').file
2
+ Log = require('grunt').log
3
+ Path = require('path')
4
+ EJS = require('ejs')
5
+ Commander = require('commander')
6
+
7
+ module.exports = class
8
+ constructor: (destination, templates) ->
9
+ @destination = destination || process.cwd()
10
+ @templates = templates || @join(__dirname, '..', '..', '..', 'templates')
11
+ @actions = []
12
+
13
+ getNamespace: (name) ->
14
+ name = name.split('/')
15
+ name.pop()
16
+ name
17
+
18
+ getBasename: (name) ->
19
+ name = name.split('/')
20
+ name.pop()
21
+
22
+ template: (source, destination, data) ->
23
+ source = @join(@templates, source...) if source instanceof Array
24
+ destination = @join(destination...) if destination instanceof Array
25
+
26
+ result = @compileTemplate source, data
27
+
28
+ @actions.push ['template', destination, result]
29
+
30
+ file: (destination, content='') ->
31
+ destination = @join(destination...) if destination instanceof Array
32
+
33
+ @actions.push ['file', destination, content]
34
+
35
+ copy: (source, destination) ->
36
+ source = @join(@templates, source...) if source instanceof Array
37
+ destination = @join(destination...) if destination instanceof Array
38
+
39
+ @actions.push ['copy', destination, source]
40
+
41
+ #
42
+ # Required but Node-only methods
43
+ #
44
+ join: ->
45
+ Path.join arguments...
46
+
47
+ compileTemplate: (source, data) ->
48
+ EJS.render File.read(source), data
49
+
50
+ #
51
+ # Node-base performer
52
+ #
53
+ perform: (callback) ->
54
+ actions = @actions.clone()
55
+ @performAction actions.pop(), actions, callback
56
+
57
+ performAction: (action, actions, callback) ->
58
+ method = "perform#{action.shift().camelize()}Action"
59
+ next = =>
60
+ if actions.length > 0
61
+ @performAction(actions.pop(), actions, callback)
62
+ else
63
+ callback()
64
+
65
+ @[method] next, action...
66
+
67
+ performCopyAction: (callback, destination, source) ->
68
+ write = =>
69
+ File.copy source, @join(@destination, destination)
70
+ Log.ok "#{destination} copied..."
71
+
72
+ if File.exists(@destination, destination)
73
+ Commander.confirm "#{destination} exists. Overwrite? ", (y) ->
74
+ write() if y
75
+ callback()
76
+ else
77
+ write()
78
+ callback()
79
+
80
+ performFileAction: (callback, destination, content) ->
81
+ write = =>
82
+ File.write(@join(@destination, destination), content)
83
+ Log.ok "#{destination} generated..."
84
+
85
+ if File.exists(@destination, destination)
86
+ Commander.confirm "#{destination} exists. Overwrite? ", (y) ->
87
+ write() if y
88
+ callback()
89
+ else
90
+ write()
91
+ callback()
92
+
93
+ performTemplateAction: -> @performFileAction arguments...
@@ -0,0 +1,20 @@
1
+ Generator = require './generator'
2
+
3
+ module.exports = class extends Generator
4
+ constructor: (@name, destination, templates) ->
5
+ super(destination, templates)
6
+ @destination = @join @destination, 'source'
7
+
8
+ generate: ->
9
+ namespace = @getNamespace @name
10
+ basename = @getBasename @name
11
+ template = if namespace.length > 0 then 'namespaced' else 'basic'
12
+
13
+ @template ['layout', "#{template}.coffee"], ['layouts', @join(namespace...), "#{basename}.coffee"],
14
+ namespace_name: namespace.map (x) -> x.camelize()
15
+ class_name: basename.camelize()
16
+ view_name: basename
17
+
18
+ @file ['templates', 'layouts', @join(namespace...), "#{basename}.jst.hamlc"]
19
+
20
+ @actions
@@ -0,0 +1,20 @@
1
+ Generator = require './generator'
2
+
3
+ module.exports = class extends Generator
4
+ constructor: (@name, destination, templates) ->
5
+ super(destination, templates)
6
+ @destination = @join @destination, 'source'
7
+
8
+ generate: ->
9
+ namespace = @getNamespace @name
10
+ basename = @getBasename @name
11
+ template = if namespace.length > 0 then 'namespaced' else 'basic'
12
+
13
+ @template ['page', "#{template}.coffee"], ['pages', @join(namespace...), "#{basename}.coffee"],
14
+ namespace_name: namespace.map (x) -> x.camelize()
15
+ class_name: basename.camelize()
16
+ view_name: basename
17
+
18
+ @file ['templates', 'pages', @join(namespace...), "#{basename}.jst.hamlc"]
19
+
20
+ @actions
@@ -0,0 +1,28 @@
1
+ Generator = require '../generator'
2
+
3
+ module.exports = class extends Generator
4
+ constructor: (@name, destination, templates) ->
5
+ super(destination, templates)
6
+ @destination = @join @destination, 'source'
7
+
8
+ generate: ->
9
+ @file ['resources', '.gitkeep']
10
+ @file ['widgets', '.gitkeep']
11
+
12
+ @copy ['application', 'base', 'routes.coffee'], ['routes.coffee']
13
+ @copy ['application', 'base', 'helpers', 'application.coffee'], ['helpers', 'application.coffee']
14
+ @copy ['application', 'base', 'layouts', 'application.coffee'], ['layouts', 'application.coffee']
15
+ @copy ['application', 'base', 'pages', 'application.coffee'], ['pages', 'application.coffee']
16
+ @copy ['application', 'base', 'pages', 'welcome', 'index.coffee'], ['pages', 'welcome', 'index.coffee']
17
+
18
+ @copy ['application', 'base', 'templates', 'layouts', 'application.jst.hamlc'],
19
+ ['templates', 'layouts', 'application.jst.hamlc']
20
+
21
+ @copy ['application', 'base', 'templates', 'pages', 'welcome', 'index.jst.hamlc'],
22
+ ['templates', 'pages', 'welcome', 'index.jst.hamlc']
23
+
24
+
25
+ @template ['application', 'base', 'application.coffee'], ['application.coffee'],
26
+ application: @name
27
+
28
+ @actions
@@ -0,0 +1,25 @@
1
+ meta = require '../../../../package.json'
2
+ Generator = require '../generator'
3
+
4
+ module.exports = class extends Generator
5
+ constructor: (@name, destination, templates) ->
6
+ destination = @join (destination || process.cwd()), @name unless destination?
7
+ super(destination, templates)
8
+
9
+ generate: ->
10
+ @file ['public', '.gitkeep']
11
+ @file ['vendor', '.gitkeep']
12
+
13
+ @copy ['application', 'standalone', '.gitignore'], ['.gitignore']
14
+ @copy ['application', 'standalone', 'bower.json'], ['bower.json']
15
+ @copy ['application', 'standalone', 'Gruntfile.coffee'], ['Gruntfile.coffee']
16
+ @copy ['application', 'standalone', 'Procfile'], ['Procfile']
17
+ @copy ['application', 'standalone', 'source', 'index.haml'], ['source', 'index.haml']
18
+
19
+ @copy ['application', 'standalone', 'stylesheets', 'application.styl'],
20
+ ['stylesheets', 'application.styl']
21
+
22
+ @template ['application', 'standalone', 'package.json'], ['package.json'],
23
+ joosy_version: meta.version
24
+
25
+ @actions
@@ -0,0 +1,16 @@
1
+ Standalone = require './project/standalone'
2
+ Base = require './project/base'
3
+
4
+ module.exports = class
5
+ constructor: (@name) ->
6
+ @standalone = new Standalone(@name)
7
+ @base = new Base(@name, @standalone.destination)
8
+
9
+ generate: ->
10
+ @standalone.generate()
11
+ @base.generate()
12
+
13
+ perform: (callback) ->
14
+ @standalone.perform =>
15
+ @base.perform =>
16
+ callback()
@@ -0,0 +1,20 @@
1
+ Generator = require './generator'
2
+
3
+ module.exports = class extends Generator
4
+ constructor: (@name, destination, templates) ->
5
+ super(destination, templates)
6
+ @destination = @join @destination, 'source'
7
+
8
+ generate: ->
9
+ namespace = @getNamespace @name
10
+ basename = @getBasename @name
11
+ template = if namespace.length > 0 then 'namespaced' else 'basic'
12
+
13
+ @template ['widget', "#{template}.coffee"], ['widgets', @join(namespace...), "#{basename}.coffee"],
14
+ namespace_name: namespace.map (x) -> x.camelize()
15
+ class_name: basename.camelize()
16
+ view_name: basename
17
+
18
+ @file ['templates', 'widgets', @join(namespace...), "#{basename}.jst.hamlc"]
19
+
20
+ @actions
data/src/joosy.coffee ADDED
@@ -0,0 +1,2 @@
1
+ #= require_tree ./joosy/core
2
+ #= require_tree ./joosy/preloaders