joosy 0.1.0.alpha → 1.0.0.RC1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. data/.codoopts +5 -0
  2. data/.gitignore +2 -0
  3. data/Gemfile +15 -2
  4. data/Gemfile.lock +102 -81
  5. data/Guardfile +16 -16
  6. data/LICENSE +22 -0
  7. data/MIT-LICENSE +2 -2
  8. data/README.md +118 -0
  9. data/app/assets/javascripts/joosy/core/application.js.coffee +53 -0
  10. data/app/assets/javascripts/joosy/core/form.js.coffee +338 -0
  11. data/app/assets/javascripts/joosy/core/helpers/form.js.coffee +72 -0
  12. data/app/assets/javascripts/joosy/core/helpers/view.js.coffee +42 -0
  13. data/app/assets/javascripts/joosy/core/helpers/widgets.js.coffee +14 -0
  14. data/app/assets/javascripts/joosy/core/joosy.js.coffee +184 -0
  15. data/app/assets/javascripts/joosy/core/layout.js.coffee +168 -0
  16. data/app/assets/javascripts/joosy/core/modules/container.js.coffee +124 -0
  17. data/app/assets/javascripts/joosy/core/modules/events.js.coffee +122 -0
  18. data/app/assets/javascripts/joosy/core/modules/filters.js.coffee +39 -0
  19. data/app/assets/javascripts/joosy/core/modules/log.js.coffee +36 -0
  20. data/app/assets/javascripts/joosy/core/modules/module.js.coffee +117 -0
  21. data/app/assets/javascripts/joosy/core/modules/renderer.js.coffee +200 -0
  22. data/app/assets/javascripts/joosy/core/modules/time_manager.js.coffee +46 -0
  23. data/app/assets/javascripts/joosy/core/modules/widgets_manager.js.coffee +87 -0
  24. data/app/assets/javascripts/joosy/core/page.js.coffee +387 -0
  25. data/app/assets/javascripts/joosy/core/preloader.js.coffee +13 -0
  26. data/app/assets/javascripts/joosy/core/resource/collection.js.coffee +175 -0
  27. data/app/assets/javascripts/joosy/core/resource/generic.js.coffee +303 -0
  28. data/app/assets/javascripts/joosy/core/resource/rest.js.coffee +244 -0
  29. data/app/assets/javascripts/joosy/core/resource/rest_collection.js.coffee +24 -0
  30. data/app/assets/javascripts/joosy/core/router.js.coffee +201 -0
  31. data/app/assets/javascripts/joosy/core/templaters/rails_jst.js.coffee +37 -0
  32. data/app/assets/javascripts/joosy/core/widget.js.coffee +85 -0
  33. data/app/assets/javascripts/joosy/preloaders/caching.js.coffee +169 -0
  34. data/app/assets/javascripts/joosy/preloaders/inline.js.coffee +56 -0
  35. data/{vendor → app}/assets/javascripts/joosy.js.coffee +0 -1
  36. data/app/helpers/joosy/sprockets_helper.rb +39 -12
  37. data/joosy.gemspec +4 -3
  38. data/lib/joosy/rails/engine.rb +12 -1
  39. data/lib/joosy/rails/version.rb +2 -2
  40. data/lib/joosy.rb +9 -0
  41. data/lib/rails/generators/joosy/application_generator.rb +15 -3
  42. data/lib/rails/generators/joosy/joosy_base.rb +2 -2
  43. data/lib/rails/generators/joosy/layout_generator.rb +8 -1
  44. data/lib/rails/generators/joosy/page_generator.rb +21 -6
  45. data/lib/rails/generators/joosy/preloader_generator.rb +14 -7
  46. data/lib/rails/generators/joosy/resource_generator.rb +29 -0
  47. data/lib/rails/generators/joosy/templates/app/helpers/application.js.coffee +4 -0
  48. data/lib/rails/generators/joosy/templates/app/layouts/application.js.coffee +1 -0
  49. data/lib/rails/generators/joosy/templates/app/layouts/template.js.coffee +1 -1
  50. data/lib/rails/generators/joosy/templates/app/pages/application.js.coffee +1 -1
  51. data/lib/rails/generators/joosy/templates/app/pages/template.js.coffee +3 -3
  52. data/lib/rails/generators/joosy/templates/app/pages/welcome/index.js.coffee +22 -0
  53. data/lib/rails/generators/joosy/templates/app/resources/template.js.coffee +2 -0
  54. data/lib/rails/generators/joosy/templates/app/routes.js.coffee +7 -1
  55. data/lib/rails/generators/joosy/templates/app/templates/layouts/application.jst.hamlc +2 -0
  56. data/lib/rails/generators/joosy/templates/app/templates/pages/welcome/index.jst.hamlc +7 -0
  57. data/lib/rails/generators/joosy/templates/app/widgets/template.js.coffee +2 -2
  58. data/lib/rails/generators/joosy/templates/app.js.coffee +4 -0
  59. data/lib/rails/generators/joosy/templates/app_preloader.js.coffee.erb +9 -12
  60. data/lib/rails/generators/joosy/templates/app_resources_predefiner.js.coffee.erb +11 -0
  61. data/lib/rails/generators/joosy/templates/preload.html.erb +5 -6
  62. data/lib/rails/generators/joosy/templates/preload.html.haml +3 -5
  63. data/lib/rails/generators/joosy/widget_generator.rb +8 -1
  64. data/lib/rails/resources_with_joosy.rb +11 -0
  65. data/spec/javascripts/helpers/spec_helper.js.coffee +25 -0
  66. data/spec/javascripts/joosy/core/application_spec.js.coffee +40 -0
  67. data/spec/javascripts/joosy/core/form_spec.js.coffee +200 -0
  68. data/spec/javascripts/joosy/core/helpers/forms_spec.js.coffee +103 -0
  69. data/spec/javascripts/joosy/core/helpers/view_spec.js.coffee +10 -0
  70. data/spec/javascripts/joosy/core/joosy_spec.js.coffee +97 -0
  71. data/spec/javascripts/joosy/core/layout_spec.js.coffee +50 -0
  72. data/spec/javascripts/joosy/core/modules/container_spec.js.coffee +32 -27
  73. data/spec/javascripts/joosy/core/modules/events_spec.js.coffee +55 -18
  74. data/spec/javascripts/joosy/core/modules/filters_spec.js.coffee +28 -27
  75. data/spec/javascripts/joosy/core/modules/log_spec.js.coffee +3 -3
  76. data/spec/javascripts/joosy/core/modules/module_spec.js.coffee +6 -15
  77. data/spec/javascripts/joosy/core/modules/renderer_spec.js.coffee +203 -0
  78. data/spec/javascripts/joosy/core/modules/time_manager_spec.js.coffee +12 -7
  79. data/spec/javascripts/joosy/core/modules/widget_manager_spec.js.coffee +31 -17
  80. data/spec/javascripts/joosy/core/page_spec.js.coffee +178 -0
  81. data/spec/javascripts/joosy/core/resource/collection_spec.js.coffee +84 -0
  82. data/spec/javascripts/joosy/core/resource/generic_spec.js.coffee +149 -0
  83. data/spec/javascripts/joosy/core/resource/rest_collection_spec.js.coffee +31 -0
  84. data/spec/javascripts/joosy/core/resource/rest_spec.js.coffee +171 -0
  85. data/spec/javascripts/joosy/core/router_spec.js.coffee +143 -0
  86. data/spec/javascripts/joosy/core/templaters/rails_jst_spec.js.coffee +25 -0
  87. data/spec/javascripts/joosy/core/widget_spec.js.coffee +40 -0
  88. data/spec/javascripts/joosy/preloaders/caching_spec.js.coffee +36 -0
  89. data/spec/javascripts/joosy/preloaders/inline_spec.js.coffee +16 -0
  90. data/spec/javascripts/support/assets/coolface.jpg +0 -0
  91. data/spec/javascripts/support/assets/okay.jpg +0 -0
  92. data/spec/javascripts/support/assets/test.js +1 -0
  93. data/spec/javascripts/support/sinon-ie-1.3.1.js +82 -0
  94. data/vendor/assets/javascripts/jquery.form.js +978 -963
  95. data/vendor/assets/javascripts/metamorph.js +409 -0
  96. data/vendor/assets/javascripts/sugar.js +1057 -366
  97. metadata +95 -50
  98. data/README.rdoc +0 -3
  99. data/lib/joosy/forms.rb +0 -47
  100. data/lib/joosy-rails.rb +0 -5
  101. data/lib/rails/generators/joosy/templates/preload.html.slim +0 -21
  102. data/tmp/javascripts/.gitignore +0 -1
  103. data/tmp/spec/javascripts/helpers/.gitignore +0 -1
  104. data/vendor/assets/javascripts/base64.js +0 -135
  105. data/vendor/assets/javascripts/inflection.js +0 -656
  106. data/vendor/assets/javascripts/joosy/core/application.js.coffee +0 -26
  107. data/vendor/assets/javascripts/joosy/core/form.js.coffee +0 -87
  108. data/vendor/assets/javascripts/joosy/core/joosy.js.coffee +0 -62
  109. data/vendor/assets/javascripts/joosy/core/layout.js.coffee +0 -38
  110. data/vendor/assets/javascripts/joosy/core/modules/container.js.coffee +0 -51
  111. data/vendor/assets/javascripts/joosy/core/modules/events.js.coffee +0 -17
  112. data/vendor/assets/javascripts/joosy/core/modules/filters.js.coffee +0 -39
  113. data/vendor/assets/javascripts/joosy/core/modules/log.js.coffee +0 -12
  114. data/vendor/assets/javascripts/joosy/core/modules/module.js.coffee +0 -28
  115. data/vendor/assets/javascripts/joosy/core/modules/time_manager.js.coffee +0 -23
  116. data/vendor/assets/javascripts/joosy/core/modules/widgets_manager.js.coffee +0 -45
  117. data/vendor/assets/javascripts/joosy/core/page.js.coffee +0 -136
  118. data/vendor/assets/javascripts/joosy/core/resource/rest.js.coffee +0 -69
  119. data/vendor/assets/javascripts/joosy/core/resource/rest_collection.js.coffee +0 -42
  120. data/vendor/assets/javascripts/joosy/core/router.js.coffee +0 -75
  121. data/vendor/assets/javascripts/joosy/core/widget.js.coffee +0 -35
  122. data/vendor/assets/javascripts/joosy/preloader/development.js.coffee +0 -27
  123. data/vendor/assets/javascripts/joosy/preloader/production.js.coffee +0 -84
@@ -0,0 +1,169 @@
1
+ #
2
+ # Preloader for libraries with localStorage cache
3
+ #
4
+ # @note The `start` callback will only be called if loading required.
5
+ # While working with cache, `complete` is the only callback that will be triggered.
6
+ #
7
+ # @example Basic usage
8
+ # libraries = [['/test1.js', 100], ['/test2.js', 500]] #100, 500 - size in bytes
9
+ #
10
+ # CachingPreloader.load libraries,
11
+ # start: -> console.log 'preloading started'
12
+ # progress: (percent) -> console.log "#{percent}% loaded"
13
+ # complete: -> console.log 'preloading finished'
14
+ #
15
+ # @mixin
16
+ #
17
+ @CachingPreloader =
18
+ #
19
+ # If set to true, localStorage cache will be avoided
20
+ #
21
+ force: false
22
+
23
+ #
24
+ # Prefix for localStorage keys
25
+ #
26
+ prefix: "cache:"
27
+
28
+ #
29
+ # Number of libraries have been loaded (increases after lib was loaded)
30
+ #
31
+ counter: 0
32
+
33
+ #
34
+ # Loads (or takes from cache) set of libraries using xhr and caches them in localStorage
35
+ # See class description for example of usage
36
+ #
37
+ # @param [Array] 2-levels array of libraries URLs i.e. [['/test1.js', 10],['/test2.js', 20]]
38
+ # Second param of inner level is a size of script in bytes. Can be undefined.
39
+ # @param [Hash] Available options:
40
+ # * start: `() -> null` to call before load starts
41
+ # * progress: `(int percents) -> null` to call each 100ms of load in progress
42
+ # * complete: `() -> null` to call after load completes
43
+ #
44
+ load: (libraries, options={}) ->
45
+ @[key] = val for key, val of options
46
+ @libraries = libraries.slice()
47
+
48
+ for lib, i in @libraries
49
+ @libraries[i] = @prefix+lib[0]
50
+
51
+ if !@force && @check()
52
+ @restore()
53
+ else
54
+ @start?.call window
55
+ @clean()
56
+ @download libraries
57
+
58
+ #
59
+ # Checks if we can load libraries or have to download them over
60
+ #
61
+ check: ->
62
+ flag = true
63
+ for name, i in @libraries
64
+ flag &&= window.localStorage.getItem(name)?
65
+ flag
66
+
67
+ #
68
+ # Escapes non-printable terminal chars before storing to localStorage to prevent IE bug
69
+ #
70
+ # @param [String] String, that will be prepared for localStorage
71
+ #
72
+ escapeStr: (str) ->
73
+ str.replace(new RegExp("\u0001", 'g'), "\\u0001").replace(new RegExp("\u000B", 'g'), "\\u000B")
74
+
75
+ #
76
+ # Gets sources of scripts from localStorage and evals them
77
+ #
78
+ restore: ->
79
+ for name, i in @libraries
80
+ window.evalGlobaly window.localStorage.getItem name
81
+ @complete?.call window, true
82
+
83
+ #
84
+ # Loads set of libraries using xhr and caches them in localStorage
85
+ #
86
+ # @param [Array] 2-levels array of libraries URLs i.e. [['/test1.js', 100],['/test2.js', 500]]
87
+ # Second param of inner level is a size of script in bytes. Can be undefined.
88
+ #
89
+ download: (libraries) ->
90
+ if libraries.length > 0
91
+ @counter += 1
92
+
93
+ lib = libraries.shift()
94
+ url = lib[0]
95
+ size = lib[1]
96
+
97
+ @ajax url, size, (xhr) =>
98
+ code = xhr.responseText
99
+ if window.navigator.appName == "Microsoft Internet Explorer"
100
+ code = @escapeStr code
101
+ window.localStorage.setItem @prefix+url, code
102
+ window.evalGlobaly xhr.responseText
103
+ @download libraries
104
+ else
105
+ @complete?.call window
106
+
107
+ #
108
+ # Runs XHR request to get single script body
109
+ # Binds poller to call @progress each 100ms if possible (not IE *doh*)
110
+ #
111
+ # @param [String] URL to download from
112
+ # @param [Float] Expected size of download (to calculate percents)
113
+ # Size can not be taken from headers since we are supposed to get gziped content
114
+ # @param [Function] `(xhr) -> null` to call after script was loaded
115
+ #
116
+ ajax: (url, size, callback) ->
117
+ if window.XMLHttpRequest
118
+ x = new XMLHttpRequest
119
+ else
120
+ x = new ActiveXObject 'Microsoft.XMLHTTP'
121
+
122
+ x.open 'GET', url, 1
123
+
124
+ x.onreadystatechange = () =>
125
+ if x.readyState > 3
126
+ clearInterval @interval
127
+ callback? x
128
+
129
+ if @progress
130
+ poller = =>
131
+ try
132
+ @progress.call window, Math.round((x.responseText.length / size) * (@counter / @libraries.length) * 100)
133
+ catch e
134
+ # ... IE?
135
+
136
+ @interval = setInterval poller, 100
137
+
138
+ x.send()
139
+
140
+ #
141
+ # Searches through localStorage for outdated entries with our prefix and removes them
142
+ #
143
+ clean: ->
144
+ i = 0
145
+
146
+ find = (arr, obj) ->
147
+ (return i if obj == x) for x in arr
148
+ return -1
149
+
150
+ while i < window.localStorage.length && key = window.localStorage.key(i)
151
+ if key.indexOf(@prefix) == 0 && find(@libraries, key) < 0
152
+ window.localStorage.removeItem key
153
+ else
154
+ i += 1
155
+
156
+ #
157
+ # Evals source at a global scope
158
+ # Don't touch it! It should be window's property, or FF3.6 will execute scripts on preloader context.
159
+ #
160
+ # @param [String] JS source to execute
161
+ #
162
+ window.evalGlobaly = (src) ->
163
+ return if src.length == 0
164
+ if window.execScript
165
+ window.execScript src
166
+ else
167
+ window.eval src
168
+
169
+ @Preloader = @CachingPreloader
@@ -0,0 +1,56 @@
1
+ #
2
+ # Preloader for libraries using `script src` without any caching magic
3
+ #
4
+ # @example Basic usage
5
+ # libraries = [['/test1.js'], ['/test2.js']]
6
+ #
7
+ # InlinePreloader.load libraries,
8
+ # start: -> console.log 'preloading started'
9
+ # complete: -> console.log 'preloading finished'
10
+ #
11
+ # @mixin
12
+ #
13
+ @InlinePreloader =
14
+ #
15
+ # Loads set of libraries by adding `script src` to DOM head
16
+ # See class description for example of usage
17
+ #
18
+ # @param [Array] 2-levels array of libraries URLs i.e. [['/test1.js'],['/test2.js']]
19
+ # @param [Hash] Available options:
20
+ # * start: `() -> null` to call before load starts:
21
+ # * complete: `() -> null` to call after load completes
22
+ #
23
+ load: (libraries, options) ->
24
+ @[key] = val for key, val of options
25
+ @start?()
26
+
27
+ if libraries.length > 0
28
+ @receive libraries.shift()[0], => @load(libraries)
29
+ else
30
+ @complete?()
31
+
32
+ #
33
+ # Loads one script by adding `script src` to DOM head
34
+ #
35
+ # @param [String] url to load script from
36
+ # @param [Function] `() -> null` to call after script was loaded and executed
37
+ #
38
+ receive: (url, callback) ->
39
+ head = document.getElementsByTagName("head")[0]
40
+ script = document.createElement "script"
41
+ script.src = url
42
+
43
+ done = false
44
+
45
+ proceed = ->
46
+ if !done && (!@readyState? || @readyState == "loaded" || @readyState == "complete")
47
+ done = true
48
+ callback?()
49
+ script.onload = script.onreadystatechange = null
50
+
51
+ script.onload = script.onreadystatechange = proceed
52
+
53
+ head.appendChild script
54
+ return undefined
55
+
56
+ @Preloader = @InlinePreloader
@@ -3,5 +3,4 @@
3
3
  #= require jquery.hashchange
4
4
  #= require jquery.form
5
5
  #= require sugar
6
- #= require inflection
7
6
  #= require_tree ./joosy/core
@@ -1,14 +1,41 @@
1
- module Joosy
2
- module SprocketsHelper
3
- def extract_sources_and_sizes_from_include_tag(name)
4
- code = javascript_include_tag name
5
- resources = code.scan(/(?:href|src)=['"]([^'"]+)['"]/).flatten
6
-
7
- resources.map do |resource|
8
- path = ::Rails.root.to_s + "/public" + resource.split('?')[0]
9
- size = File.size(path) rescue false
10
- [resource, size]
11
- end.to_json.html_safe
1
+ require 'uri'
2
+
3
+ module Joosy::SprocketsHelper
4
+ def extract_sources_and_sizes_from_include_tag(name)
5
+ code = javascript_include_tag name
6
+ resources = code.scan(/(?:href|src)=['"]([^'"]+)['"]/).flatten
7
+
8
+ resources.map do |resource|
9
+ uri = URI.parse resource
10
+ path = ::Rails.root.to_s + "/public" + uri.path
11
+ size = File.size(path) rescue 0
12
+ [resource, size]
13
+ end.to_json.html_safe
14
+ end
15
+
16
+ def require_joosy_preloader_for(app_asset, options={})
17
+ preloader_asset = "joosy/preloaders/#{options[:preloader] || 'caching'}"
18
+ force_preloader = options[:force] || false
19
+
20
+ if force_preloader
21
+ require_asset preloader_asset
22
+ else
23
+ require_asset Rails.env == 'development' ? app_asset : preloader_asset
24
+ end
25
+ end
26
+
27
+ def self.joosy_resources(namespaces=nil)
28
+ predefined = {}
29
+ filtered_resources = Joosy::Rails::Engine.resources
30
+ if namespaces
31
+ namespaces = Array.wrap namespaces
32
+ filtered_resources = filtered_resources.select{|key, _| namespaces.include? key }
33
+ end
34
+ filtered_resources.each do |namespace, resources|
35
+ next unless resources && resources.size > 0
36
+ joosy_namespace = namespace.to_s.camelize.split('::').join('.')
37
+ predefined[joosy_namespace] = resources
12
38
  end
39
+ predefined
13
40
  end
14
- end
41
+ end
data/joosy.gemspec CHANGED
@@ -6,19 +6,20 @@ Gem::Specification.new do |s|
6
6
  s.platform = Gem::Platform::RUBY
7
7
  s.summary = "Joosy Framework support for Ruby on Rails"
8
8
  s.email = "boris@roundlake.ru"
9
- s.homepage = "http://github.com/roundlake/joosy-rails"
9
+ s.homepage = "http://github.com/roundlake/joosy"
10
10
  s.description = "A gem wrapper to include Joosy via the asset pipeline."
11
11
  s.authors = ['Boris Staal', 'Andrew Shaydurov', 'Peter Zotov', 'Alexander Pavlenko']
12
12
 
13
13
  s.files = `git ls-files`.split("\n")
14
14
  s.require_paths = ["lib"]
15
15
 
16
- s.add_dependency 'rails', ">= 3.0.0"
16
+ s.add_dependency 'rails', ">= 3.1.0"
17
17
  s.add_dependency 'coffee-rails'
18
18
  s.add_dependency 'jquery-rails'
19
+ s.add_dependency 'haml_coffee_assets'
20
+ s.add_dependency 'i18n-js'
19
21
 
20
22
  s.add_development_dependency 'guard'
21
- s.add_development_dependency 'guard-shell'
22
23
  s.add_development_dependency 'guard-coffeescript'
23
24
  s.add_development_dependency 'guard-sprockets'
24
25
  s.add_development_dependency 'jasmine'
@@ -3,7 +3,18 @@ require 'rails/engine'
3
3
  module Joosy
4
4
  module Rails
5
5
  class Engine < ::Rails::Engine
6
- # auto wire
6
+
7
+ cattr_accessor :resources
8
+ self.resources = {}
9
+
10
+ initializer 'joosy.extend.sprockets' do |app|
11
+ ActiveSupport.on_load(:action_view) do
12
+ app.assets.context_class.instance_eval do
13
+ include ::Joosy::SprocketsHelper
14
+ end
15
+ end
16
+ end
17
+
7
18
  end
8
19
  end
9
20
  end
@@ -1,5 +1,5 @@
1
1
  module Joosy
2
2
  module Rails
3
- VERSION = "0.1.0.alpha"
3
+ VERSION = "1.0.0.RC1"
4
4
  end
5
- end
5
+ end
data/lib/joosy.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'haml_coffee_assets'
2
+ require 'jquery-rails'
3
+ require 'coffee-rails'
4
+
5
+ require 'joosy/rails/engine'
6
+ require 'joosy/rails/version'
7
+ require 'rails/resources_with_joosy'
8
+
9
+ require 'i18n-js'
@@ -6,24 +6,36 @@ module Joosy
6
6
  source_root File.join(File.dirname(__FILE__), 'templates')
7
7
 
8
8
  def create_files
9
- self.destination_root = "app/assets/javascripts"
9
+ super
10
10
 
11
11
  template "app.js.coffee", "#{file_path}.js.coffee"
12
12
 
13
+ template "app_resources_predefiner.js.coffee.erb", "#{file_path}_resources_predefiner.js.coffee.erb"
14
+
13
15
  empty_directory file_path
14
16
 
15
17
  template "app/routes.js.coffee", "#{file_path}/routes.js.coffee"
16
18
 
19
+ empty_directory "#{file_path}/helpers"
20
+ template "app/helpers/application.js.coffee", "#{file_path}/helpers/application.js.coffee"
21
+
17
22
  empty_directory "#{file_path}/layouts"
18
23
  template "app/layouts/application.js.coffee", "#{file_path}/layouts/application.js.coffee"
19
24
 
20
- empty_directory "#{file_path}/pages"
25
+ empty_directory "#{file_path}/pages/welcome"
21
26
  template "app/pages/application.js.coffee", "#{file_path}/pages/application.js.coffee"
27
+ template "app/pages/welcome/index.js.coffee", "#{file_path}/pages/welcome/index.js.coffee"
28
+
29
+ empty_directory "#{file_path}/templates/layouts"
30
+ template "app/templates/layouts/application.jst.hamlc", "#{file_path}/templates/layouts/application.jst.hamlc"
31
+
32
+ empty_directory "#{file_path}/templates/pages/welcome"
33
+ template "app/templates/pages/welcome/index.jst.hamlc", "#{file_path}/templates/pages/welcome/index.jst.hamlc"
22
34
 
23
35
  empty_directory_with_gitkeep "#{file_path}/widgets"
36
+ empty_directory_with_gitkeep "#{file_path}/resources"
24
37
 
25
38
  empty_directory_with_gitkeep "#{file_path}/templates/layouts"
26
- empty_directory_with_gitkeep "#{file_path}/templates/pages"
27
39
  empty_directory_with_gitkeep "#{file_path}/templates/widgets"
28
40
  end
29
41
  end
@@ -3,8 +3,8 @@ require 'rails/generators/named_base'
3
3
  module Rails
4
4
  module Generators
5
5
  class JoosyBase < ::Rails::Generators::NamedBase
6
- class_option :template_kind, :type => :string, :aliases => "-T", :default => 'jade',
7
- :desc => "Generate templates with specified extension (default: .jade)"
6
+ class_option :template_kind, :type => :string, :aliases => "-T", :default => 'hamlc',
7
+ :desc => "Generate templates with specified extension (default: .hamlc)"
8
8
 
9
9
  class_option :skip_git, :type => :boolean, :aliases => "-G", :default => false,
10
10
  :desc => "Skip Git keeps"
@@ -18,7 +18,14 @@ module Joosy
18
18
  protected
19
19
 
20
20
  def app_path
21
- File.join class_path
21
+ unless class_path.size == 1
22
+ puts <<HELP
23
+ Usage: rails generate joosy:layout joosy_app_name/layout_name
24
+ Tip: do not add Layout suffix to layout_name
25
+ HELP
26
+ exit 1
27
+ end
28
+ class_path[0]
22
29
  end
23
30
  end
24
31
  end
@@ -8,21 +8,36 @@ module Joosy
8
8
  def create_files
9
9
  super
10
10
 
11
- empty_directory "#{app_path}/pages"
12
- template "app/pages/template.js.coffee", "#{app_path}/pages/#{layout_name}/#{file_name}.js.coffee"
11
+ empty_directory "#{app_path}/pages/#{namespace_path}"
12
+ template "app/pages/template.js.coffee", "#{app_path}/pages/#{namespace_path}/#{file_name}.js.coffee"
13
13
 
14
- empty_directory "#{app_path}/templates/pages/#{layout_name}"
15
- create_file "#{app_path}/templates/pages/#{layout_name}/#{file_name}.jst.#{options[:template_kind]}"
14
+ empty_directory "#{app_path}/templates/pages/#{namespace_path}"
15
+ create_file "#{app_path}/templates/pages/#{namespace_path}/#{file_name}.jst.#{options[:template_kind]}"
16
16
  end
17
17
 
18
18
  protected
19
19
 
20
20
  def app_path
21
- File.join class_path[0..-2]
21
+ if class_path.size < 2
22
+ puts <<HELP
23
+ Usage: rails generate joosy:page joosy_app_name/page_namespace/page_name
24
+ Tip: do not add Page suffix to page_name
25
+ HELP
26
+ exit 1
27
+ end
28
+ class_path[0]
29
+ end
30
+
31
+ def namespace_path
32
+ File.join class_path[1..-1]
33
+ end
34
+
35
+ def namespace_name
36
+ class_path[1..-1].map(&:camelize).join '.'
22
37
  end
23
38
 
24
39
  def layout_name
25
- class_path.last
40
+ class_path[1]
26
41
  end
27
42
  end
28
43
  end
@@ -4,21 +4,28 @@ module Joosy
4
4
  module Generators
5
5
  class PreloaderGenerator < ::Rails::Generators::NamedBase
6
6
  class_option :template_engine, :type => :string,
7
- :desc => "Generate templates for specified engine."
7
+ :desc => "Generate templates for specified engine."
8
8
 
9
9
  source_root File.join(File.dirname(__FILE__), 'templates')
10
10
 
11
11
  def create_preloader_files
12
- template "app_preloader.js.coffee.erb", "app/assets/javascripts/#{file_path}_preloader.js.coffee.erb"
12
+ unless class_path.empty?
13
+ puts <<HELP
14
+ Usage: rails generate joosy:preloader joosy_app_name
15
+ HELP
16
+ exit 1
17
+ end
13
18
 
14
- empty_directory "app/controllers/#{File.join class_path}"
15
- template "app_controller.rb", "app/controllers/#{file_path}_controller.rb"
19
+ template "app_preloader.js.coffee.erb", "app/assets/javascripts/#{file_name}_preloader.js.coffee.erb"
16
20
 
17
- empty_directory "app/views/layouts/#{File.join class_path}"
21
+ empty_directory "app/controllers"
22
+ template "app_controller.rb", "app/controllers/#{file_name}_controller.rb"
23
+
24
+ empty_directory "app/views/layouts"
18
25
  template "preload.html.#{options[:template_engine]}",
19
- "app/views/layouts/#{file_path}.html.#{options[:template_engine]}"
26
+ "app/views/layouts/#{file_name}.html.#{options[:template_engine]}"
20
27
 
21
- route "match '#{file_path}' => '#{file_path}#index'"
28
+ route "match '#{file_name}' => '#{file_name}#index'"
22
29
  end
23
30
  end
24
31
  end
@@ -0,0 +1,29 @@
1
+ require 'rails/generators/joosy/joosy_base'
2
+
3
+ module Joosy
4
+ module Generators
5
+ class ResourceGenerator < ::Rails::Generators::JoosyBase
6
+ source_root File.join(File.dirname(__FILE__), 'templates')
7
+
8
+ def create_files
9
+ super
10
+
11
+ empty_directory "#{app_path}/resources"
12
+ template "app/resources/template.js.coffee", "#{app_path}/resources/#{file_name}.js.coffee"
13
+ end
14
+
15
+ protected
16
+
17
+ def app_path
18
+ unless class_path.size == 1
19
+ puts <<HELP
20
+ Usage: rails generate joosy:resource joosy_app_name/resource_name
21
+ Tip: resource_name is better to be singular
22
+ HELP
23
+ exit 1
24
+ end
25
+ class_path[0]
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,4 @@
1
+ Joosy.helpers 'Application', ->
2
+
3
+ # helloWorld = (name) ->
4
+ # "Hello World, #{name}"
@@ -1 +1,2 @@
1
1
  class @ApplicationLayout extends Joosy.Layout
2
+ @view 'application'
@@ -1,2 +1,2 @@
1
1
  class @<%= file_name.camelize %>Layout extends ApplicationLayout
2
- view: JST['<%= app_path %>/templates/layouts/<%= file_name %>']
2
+ @view '<%= file_name %>'
@@ -1 +1 @@
1
- class @ApplicationPage extends Joosy.Page
1
+ class @ApplicationPage extends Joosy.Page
@@ -1,5 +1,5 @@
1
- Joosy.namespace '<%= layout_name.camelize %>', ->
1
+ Joosy.namespace '<%= namespace_name %>', ->
2
2
 
3
3
  class @<%= file_name.camelize %>Page extends ApplicationPage
4
- layout: <%= layout_name.camelize %>Layout
5
- view: JST['<%= app_path %>/templates/pages/<%= layout_name %>/<%= file_name %>']
4
+ @layout ApplicationLayout
5
+ @view '<%= file_name %>'
@@ -0,0 +1,22 @@
1
+ Joosy.namespace 'Welcome', ->
2
+
3
+ class @IndexPage extends ApplicationPage
4
+ @layout ApplicationLayout
5
+ @view 'index'
6
+
7
+ @afterLoad ->
8
+ @startHeartbeat()
9
+ @content.css
10
+ 'padding-top': "#{$(window).height() / 2 - 160}px"
11
+
12
+ elements:
13
+ content: '#content'
14
+ joosy: '.joosy'
15
+
16
+ events:
17
+ 'mouseover $joosy': -> clearInterval @heartbeat
18
+ 'mouseout $joosy': 'startHeartbeat'
19
+
20
+ startHeartbeat: ->
21
+ @heartbeat = @setInterval 1500, =>
22
+ @joosy.animate({opacity: 0.8}, 300).animate({opacity: 1}, 300)
@@ -0,0 +1,2 @@
1
+ class @<%= file_name.camelize %> extends Joosy.Resource.REST
2
+ @entity '<%= file_name %>'
@@ -1,2 +1,8 @@
1
1
  Joosy.Router.map
2
- 404 : (path) -> alert "Page '#{path}' was not found :("
2
+ 404 : (path) -> alert "Page '#{path}' was not found :("
3
+ '/' : Welcome.IndexPage
4
+ # '/resources' :
5
+ # '/' : Resource.IndexPage
6
+ # '/:id' : Resource.ShowPage
7
+ # '/:id/edit' : Resource.EditPage
8
+ # '/new' : Resource.EditPage
@@ -0,0 +1,2 @@
1
+ #page{:style => 'font-family: "Lucida Grande", "Verdana"; text-align: center'}
2
+ .content{:id => @yield()}
@@ -0,0 +1,7 @@
1
+ #wrapper
2
+ #content
3
+ %h1 Welcome aboard
4
+ %h2{:style => 'margin-bottom: 30px'} You’re still riding Ruby on Rails.
5
+ .joosy{:style => 'background: #F71; border-radius: 10px; width: 250px; display: inline-block'}
6
+ %div{:style => 'color: #FFF; padding: 10px;'}
7
+ But it's so joosy this time!
@@ -1,2 +1,2 @@
1
- class @<%= file_name.camelize %>Widget extends Joosy.Layout
2
- view: JST['<%= app_path %>/templates/widgets/<%= file_name %>']
1
+ class @<%= file_name.camelize %>Widget extends Joosy.Widget
2
+ @view '<%= file_name %>'
@@ -1,6 +1,10 @@
1
+ #= require hamlcoffee
1
2
  #= require joosy
2
3
  #
4
+ #= require_tree ./<%= file_name %>/helpers
3
5
  #= require_tree ./<%= file_name %>/templates
6
+ #= require_tree ./<%= file_name %>/resources
7
+ #= require ./<%= file_name %>_resources_predefiner
4
8
  #= require_tree ./<%= file_name %>/widgets
5
9
  #= require_tree ./<%= file_name %>/layouts
6
10
  #= require_tree ./<%= file_name %>/pages
@@ -1,16 +1,13 @@
1
- <%= '<% require_asset "joosy/preloader/#{Rails.env}" %'+'>' %>
1
+ <%= "<%= require_joosy_preloader_for '" %><%= file_name %><%= "', preloader: 'caching', force: false %" + ">" %>
2
2
 
3
3
  bootstrap = ->
4
- $('#preloader').slideUp ->
5
- location.hash = '!/' if !location.hash
6
-
7
- Joosy.debug = window.preload.development
8
- Joosy.Application.initialize('#application')
4
+ $('#preloader').remove()
5
+ Joosy.Application.initialize '<%= file_name %>','#application',
6
+ environment: window.joosy.environment
7
+ debug: false
9
8
 
10
9
  window.onload = ->
11
- Preloader.force = false
12
- Preloader.complete = bootstrap
13
- Preloader.start = -> document.getElementById('preloader').style.display = 'block'
14
- Preloader.progress = (percent) -> document.getElementById('percents').innerHTML = percent + '%'
15
-
16
- Preloader.load window.preload.libraries
10
+ Preloader.load window.joosy.libraries,
11
+ complete: bootstrap
12
+ start: -> document.getElementById('preloader').style.display = 'block'
13
+ progress: (percent) -> document.getElementById('percents').innerHTML = percent + '%'