extjs-mvc 0.3.10 → 0.4.0.a

Sign up to get free protection for your applications and to get access to all the features.
Files changed (204) hide show
  1. data/LICENSE +1 -1
  2. data/README.rdoc +5 -173
  3. data/Rakefile +18 -20
  4. data/VERSION +1 -1
  5. data/bin/xmvc +13 -0
  6. data/lib/extjs-mvc/README +20 -0
  7. data/lib/extjs-mvc/builder.rb +83 -0
  8. data/lib/extjs-mvc/builders/all_builder.rb +15 -0
  9. data/lib/extjs-mvc/builders/app_builder.rb +36 -0
  10. data/lib/extjs-mvc/builders/base.rb +138 -0
  11. data/lib/extjs-mvc/builders/css_builder.rb +36 -0
  12. data/lib/extjs-mvc/builders/docs_builder.rb +20 -0
  13. data/lib/extjs-mvc/builders/mvc_builder.rb +33 -0
  14. data/lib/extjs-mvc/builders/plugin_builder.rb +53 -0
  15. data/lib/extjs-mvc/cli.rb +52 -0
  16. data/lib/extjs-mvc/generator.rb +79 -0
  17. data/lib/extjs-mvc/generators/app.rb +57 -0
  18. data/lib/extjs-mvc/generators/base.rb +53 -0
  19. data/lib/extjs-mvc/generators/controller.rb +41 -0
  20. data/lib/extjs-mvc/generators/model.rb +41 -0
  21. data/lib/extjs-mvc/generators/scaffold.rb +17 -0
  22. data/lib/extjs-mvc/generators/templates/Controller.js +17 -0
  23. data/lib/extjs-mvc/generators/templates/Model.js +9 -0
  24. data/lib/extjs-mvc/generators/templates/ModelSpec.js +12 -0
  25. data/lib/extjs-mvc/generators/templates/View.js +16 -0
  26. data/lib/extjs-mvc/generators/templates/_Action.js +7 -0
  27. data/lib/extjs-mvc/generators/templates/app/README.rdoc +152 -0
  28. data/lib/extjs-mvc/generators/templates/app/app/App.js +64 -0
  29. data/lib/extjs-mvc/generators/templates/app/app/controllers/ApplicationController.js +10 -0
  30. data/lib/extjs-mvc/generators/templates/app/app/controllers/HomeController.js +10 -0
  31. data/lib/extjs-mvc/generators/templates/app/app/views/home/Index.js +17 -0
  32. data/lib/extjs-mvc/generators/templates/app/app/views/layout/Menu.js +23 -0
  33. data/lib/extjs-mvc/generators/templates/app/config/application.js +1 -0
  34. data/lib/extjs-mvc/generators/templates/app/config/boot.js +67 -0
  35. data/lib/extjs-mvc/generators/templates/app/config/build.xml +77 -0
  36. data/lib/extjs-mvc/generators/templates/app/config/database.js +4 -0
  37. data/lib/extjs-mvc/generators/templates/app/config/environment.json +58 -0
  38. data/lib/extjs-mvc/generators/templates/app/config/environments/development.json +1 -0
  39. data/lib/extjs-mvc/generators/templates/app/config/environments/production.json +4 -0
  40. data/lib/extjs-mvc/generators/templates/app/config/routes.js +27 -0
  41. data/lib/extjs-mvc/generators/templates/app/config/settings.yml +3 -0
  42. data/lib/extjs-mvc/generators/templates/app/public/index.html +19 -0
  43. data/lib/extjs-mvc/generators/templates/app/public/stylesheets/ext-mvc-all.css +49 -0
  44. data/{test/active_record_test.rb → lib/extjs-mvc/generators/templates/app/spec/SpecHelper.js} +0 -0
  45. data/lib/extjs-mvc/generators/templates/app/spec/index.html +66 -0
  46. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/EXAMPLE.html +68 -0
  47. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/LICENSE +22 -0
  48. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/README.markdown +307 -0
  49. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/lib/jquery-1.2.3.js +3408 -0
  50. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/lib/jquery.fn.js +29 -0
  51. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/lib/jquery.print.js +108 -0
  52. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/lib/screw.assets.js +36 -0
  53. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/lib/screw.behaviors.js +91 -0
  54. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/lib/screw.builder.js +80 -0
  55. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/lib/screw.css +90 -0
  56. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/lib/screw.events.js +42 -0
  57. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/lib/screw.matchers.js +145 -0
  58. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/lib/screw.server.js +21 -0
  59. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/spec/behaviors_spec.js +178 -0
  60. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/spec/matchers_spec.js +237 -0
  61. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/spec/print_spec.js +119 -0
  62. data/{test/controller_test.rb → lib/extjs-mvc/generators/templates/app/vendor/screw-unit/spec/spec_helper.js} +0 -0
  63. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/spec/suite.html +18 -0
  64. data/lib/extjs-mvc/generators/templates/scaffold/ScaffoldController.js +18 -0
  65. data/lib/extjs-mvc/generators/view.rb +29 -0
  66. data/lib/extjs-mvc/plugin.rb +105 -0
  67. data/lib/extjs-mvc/scripts.rb +15 -0
  68. data/lib/extjs-mvc/settings.rb +75 -0
  69. data/lib/extjs-mvc/setup.rb +5 -0
  70. data/lib/extjs-mvc/stats.rb +241 -0
  71. data/lib/extjs-mvc/test.rb +11 -0
  72. data/lib/extjs-mvc/testserver.ru +95 -0
  73. data/lib/extjs-mvc/ui.rb +58 -0
  74. data/lib/extjs-mvc/update.rb +73 -0
  75. data/lib/extjs-mvc.rb +70 -32
  76. data/lib/js/App.js +219 -0
  77. data/lib/js/MVC.js +260 -0
  78. data/lib/js/Presenter.js +52 -0
  79. data/lib/js/README.rdoc +69 -0
  80. data/lib/js/build +21 -0
  81. data/lib/js/controller/Controller.js +278 -0
  82. data/lib/js/controller/CrudController.js +460 -0
  83. data/lib/js/lib/Array.js +26 -0
  84. data/lib/js/lib/Booter.js +415 -0
  85. data/lib/js/lib/ClassManager.js +191 -0
  86. data/lib/js/lib/ControllerClassManager.js +95 -0
  87. data/lib/js/lib/Dependencies.js +44 -0
  88. data/lib/js/lib/DispatchMatcher.js +98 -0
  89. data/lib/js/lib/Dispatcher.js +129 -0
  90. data/lib/js/lib/Environment.js +43 -0
  91. data/lib/js/lib/Inflector.js +138 -0
  92. data/lib/js/lib/ModelClassManager.js +19 -0
  93. data/lib/js/lib/Route.js +139 -0
  94. data/lib/js/lib/Router.js +282 -0
  95. data/lib/js/lib/String.js +94 -0
  96. data/lib/js/lib/ViewClassManager.js +229 -0
  97. data/lib/js/lib/notes.txt +32 -0
  98. data/lib/js/model/AdapterManager.js +30 -0
  99. data/lib/js/model/Association.js +26 -0
  100. data/lib/js/model/Base.js +63 -0
  101. data/lib/js/model/BelongsToAssociation.js +116 -0
  102. data/lib/js/model/Cache.js +131 -0
  103. data/lib/js/model/HasManyAssociation.js +160 -0
  104. data/lib/js/model/Model.js +331 -0
  105. data/lib/js/model/UrlBuilder.js +106 -0
  106. data/lib/js/model/adapters/AbstractAdapter.js +296 -0
  107. data/lib/js/model/adapters/MemoryAdapter.js +103 -0
  108. data/lib/js/model/adapters/RESTAdapter.js +345 -0
  109. data/lib/js/model/adapters/RESTJSONAdapter.js +68 -0
  110. data/lib/js/model/adapters/notes.txt +42 -0
  111. data/lib/js/model/associations/Association.js +192 -0
  112. data/lib/js/model/associations/notes.txt +87 -0
  113. data/lib/js/model/validations/Errors.js +136 -0
  114. data/lib/js/model/validations/Plugin.js +139 -0
  115. data/lib/js/model/validations/Validations.js +276 -0
  116. data/lib/js/notes/Charts.graffle +0 -0
  117. data/lib/js/overrides/Ext.Component.js +21 -0
  118. data/lib/js/overrides/Ext.extend.js +142 -0
  119. data/lib/js/spec/Array.spec.js +15 -0
  120. data/lib/js/spec/ExtMVC.spec.js +65 -0
  121. data/lib/js/spec/Model.spec.js +370 -0
  122. data/lib/js/spec/OS.spec.js +83 -0
  123. data/lib/js/spec/Router.spec.js +99 -0
  124. data/lib/js/spec/SpecHelper.js +106 -0
  125. data/lib/js/spec/String.spec.js +83 -0
  126. data/lib/js/spec/model/AbstractAdapter.spec.js +49 -0
  127. data/lib/js/spec/model/Associations.spec.js +99 -0
  128. data/lib/js/spec/model/Cache.spec.js +5 -0
  129. data/lib/js/spec/model/RESTAdapter.spec.js +19 -0
  130. data/lib/js/spec/model/ValidationErrors.spec.js +64 -0
  131. data/lib/js/spec/model/Validations.spec.js +166 -0
  132. data/lib/js/spec/model/ValidationsPlugin.spec.js +108 -0
  133. data/lib/js/spec/suite.html +60 -0
  134. data/lib/js/specs-old/JSSpec.css +216 -0
  135. data/lib/js/specs-old/JSSpec.js +1512 -0
  136. data/lib/js/specs-old/all.html +66 -0
  137. data/lib/js/specs-old/base.js +14 -0
  138. data/lib/js/specs-old/controller.js +17 -0
  139. data/lib/js/specs-old/diff_match_patch.js +1 -0
  140. data/lib/js/specs-old/model.js +70 -0
  141. data/lib/js/specs-old/route.js +38 -0
  142. data/lib/js/specs-old/router.js +59 -0
  143. data/lib/js/specs-old/string.js +22 -0
  144. data/lib/js/testrunner/JSpecFormatter.js +111 -0
  145. data/lib/js/testrunner/TestClient.js +181 -0
  146. data/lib/js/testrunner/TestGrid.js +351 -0
  147. data/lib/js/testrunner/TestRunner.js +110 -0
  148. data/lib/js/testrunner/TestViewport.js +94 -0
  149. data/lib/js/vendor/screw-unit/EXAMPLE.html +68 -0
  150. data/lib/js/vendor/screw-unit/LICENSE +22 -0
  151. data/lib/js/vendor/screw-unit/README.markdown +307 -0
  152. data/lib/js/vendor/screw-unit/lib/jquery-1.2.3.js +3408 -0
  153. data/lib/js/vendor/screw-unit/lib/jquery.fn.js +29 -0
  154. data/lib/js/vendor/screw-unit/lib/jquery.print.js +108 -0
  155. data/lib/js/vendor/screw-unit/lib/screw.assets.js +36 -0
  156. data/lib/js/vendor/screw-unit/lib/screw.behaviors.js +91 -0
  157. data/lib/js/vendor/screw-unit/lib/screw.builder.js +80 -0
  158. data/lib/js/vendor/screw-unit/lib/screw.css +91 -0
  159. data/lib/js/vendor/screw-unit/lib/screw.events.js +42 -0
  160. data/lib/js/vendor/screw-unit/lib/screw.matchers.js +145 -0
  161. data/lib/js/vendor/screw-unit/lib/screw.server.js +21 -0
  162. data/lib/js/vendor/screw-unit/spec/behaviors_spec.js +178 -0
  163. data/lib/js/vendor/screw-unit/spec/matchers_spec.js +237 -0
  164. data/lib/js/vendor/screw-unit/spec/print_spec.js +119 -0
  165. data/{test/data_mapper_test.rb → lib/js/vendor/screw-unit/spec/spec_helper.js} +0 -0
  166. data/lib/js/vendor/screw-unit/spec/suite.html +18 -0
  167. data/lib/js/view/FormWindow.js +184 -0
  168. data/lib/js/view/HasManyEditorGridPanel.js +211 -0
  169. data/lib/js/view/scaffold/Edit.js +46 -0
  170. data/lib/js/view/scaffold/Index.js +561 -0
  171. data/lib/js/view/scaffold/New.js +20 -0
  172. data/lib/js/view/scaffold/ScaffoldFormPanel.js +255 -0
  173. data/test/helper.rb +10 -0
  174. data/test/test_extjs-mvc-gem.rb +7 -0
  175. metadata +232 -56
  176. data/README +0 -12
  177. data/lib/controller/controller.rb +0 -28
  178. data/lib/core_ext/array/extract_options.rb +0 -15
  179. data/lib/extjs/component.rb +0 -71
  180. data/lib/extjs/data/store.rb +0 -131
  181. data/lib/helpers/component.rb +0 -37
  182. data/lib/helpers/store.rb +0 -7
  183. data/lib/model/active_record.rb +0 -89
  184. data/lib/model/base.rb +0 -370
  185. data/lib/model/data_mapper.rb +0 -66
  186. data/lib/model/mongo_mapper.rb +0 -64
  187. data/lib/test/macros.rb +0 -20
  188. data/test/app/config/application.rb +0 -70
  189. data/test/app/config/database.yml +0 -3
  190. data/test/app/db/schema.rb +0 -75
  191. data/test/app/models/active_record/address.rb +0 -4
  192. data/test/app/models/active_record/data_type.rb +0 -3
  193. data/test/app/models/active_record/group.rb +0 -4
  194. data/test/app/models/active_record/house.rb +0 -4
  195. data/test/app/models/active_record/location.rb +0 -5
  196. data/test/app/models/active_record/person.rb +0 -4
  197. data/test/app/models/active_record/user.rb +0 -6
  198. data/test/app/models/active_record/user_group.rb +0 -4
  199. data/test/component_test.rb +0 -15
  200. data/test/debug.log +0 -2969
  201. data/test/model_test.rb +0 -526
  202. data/test/mongo_mapper_test.rb +0 -0
  203. data/test/store_test.rb +0 -0
  204. data/test/test_helper.rb +0 -32
@@ -0,0 +1,53 @@
1
+ module ExtJS
2
+ module MVC
3
+ class PluginBuilder < Builder
4
+ # returns an array of PluginBuilder instances based on input from the command line.
5
+ # The sole argument should be an array, where the first element will usually be a plugin name, or 'all'
6
+ def self.instances(args = [])
7
+ name = args[0] || 'all'
8
+
9
+ if name == 'all'
10
+ self.all_plugin_names.collect {|name| ExtMVC::PluginBuilder.new(name)}
11
+ else
12
+ [ExtMVC::PluginBuilder.new(name)]
13
+ end
14
+ end
15
+
16
+ attr_accessor :name
17
+
18
+ def initialize(name)
19
+ @name = name
20
+ end
21
+
22
+ def output_filename
23
+ "#{directory_name}/#{name}-all.js"
24
+ end
25
+
26
+ def message
27
+ "Built the #{name} plugin"
28
+ end
29
+
30
+ def description
31
+ "The #{name} plugin (#{directory_name})"
32
+ end
33
+
34
+ def directory_name
35
+ "#{ExtMVC::PluginBuilder.plugins_directory}/#{@name}"
36
+ end
37
+
38
+ # The plugins directory, relative to the directory the build command is run from
39
+ def self.plugins_directory
40
+ "vendor/plugins"
41
+ end
42
+
43
+ private
44
+
45
+ #Gets the name of each plugin directory inside vendor/plugins and calls self.plugin with it
46
+ def self.all_plugin_names
47
+ Dir.entries(self.plugins_directory).select {|fileName|
48
+ File.directory?("#{self.plugins_directory}/#{fileName}") && (fileName =~ /^\./) != 0
49
+ }
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,52 @@
1
+ require 'thor'
2
+
3
+ require 'jammit-core'
4
+ require 'jammit-core/cli'
5
+
6
+ module ExtJS
7
+ module MVC
8
+ class CLI < Thor
9
+ ARGV = ::ARGV.dup
10
+
11
+ desc "generate", "Generate model, controller, view or app"
12
+ def generate(which, *params)
13
+ ExtJS::MVC.ensure_in_app unless which == 'app'
14
+ ExtJS::MVC::Generator.dispatch(which, *params)
15
+ end
16
+
17
+ desc "build", "Build stuff"
18
+ def build(name = :all, *params)
19
+ ExtJS::MVC.ensure_in_app
20
+ ExtJS::MVC::BuilderManager.dispatch(name, *params)
21
+ end
22
+
23
+ desc "plugin", "Manage plugins"
24
+ def plugin
25
+ ExtJS::MVC.ensure_in_app
26
+ ExtJS::MVC::Plugin.new('Frak')
27
+ end
28
+
29
+ desc "stats", "View code statistics"
30
+ def stats
31
+ ExtJS::MVC.ensure_in_app
32
+ #ExtJS::MVC::Stats.new('Frak')
33
+ end
34
+
35
+ desc "namespace", "Change the application's namespace"
36
+ def namespace(name)
37
+ ExtJS::MVC.ensure_in_app
38
+ ExtJS::MVC::Generator.dispatch("namespace", name)
39
+ end
40
+
41
+ def initialize(args=ARGV, config={}, options={})
42
+
43
+ ExtJS::MVC.ui = UI::Shell.new(shell)
44
+
45
+ super
46
+ end
47
+
48
+ private
49
+
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,79 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+
3
+ require 'hpricot'
4
+ require 'generators/base'
5
+ require 'generators/app'
6
+ require 'generators/model'
7
+ require 'generators/view'
8
+ require 'generators/controller'
9
+ require 'generators/scaffold'
10
+
11
+ module ExtJS
12
+ module MVC
13
+ module Generator
14
+
15
+ @@generators = %w(app model controller scaffold view namespace)
16
+ def self.dispatch(generator, *params)
17
+
18
+ unless @@generators.include?(generator)
19
+ raise ArgumentError.new("Must use one of the following: " + @@generators.join(", ").downcase)
20
+ end
21
+
22
+ name = params.shift
23
+
24
+ case generator
25
+ when "app"
26
+ App.new(name).generate!
27
+ when "model"
28
+ fields = params.select {|arg| arg != "--force"}.collect {|f| f.split(":")}
29
+ Model.new(name, fields).generate!
30
+ when "controller"
31
+ actions = params.select {|arg| arg != "--force"}
32
+ Controller.new(name, actions).generate!
33
+ when "scaffold"
34
+ fields = params.select {|arg| arg != "--force"}.collect {|f| f.split(":")}
35
+ Scaffold.new(name, fields).generate!
36
+ when "view"
37
+ package = name
38
+ name = params.shift
39
+ View.new(package, name).generate!
40
+ when "namespace"
41
+ self.namespace(name)
42
+
43
+ end
44
+ end
45
+
46
+ # overwrites all instances of 'MyApp' with the namespace provided
47
+ def self.namespace(namespace)
48
+ current = ExtJS::MVC.namespace
49
+
50
+ configs = %w(
51
+ config/settings.yml
52
+ config/application.js
53
+ )
54
+ Dir["app/controllers/*.js"].each do |f|
55
+ write_namespace(f, current, namespace)
56
+ end
57
+ Dir["app/views/*/*.js"].each do |f|
58
+ write_namespace(f, current, namespace)
59
+ end
60
+ configs.each {|f|
61
+ write_namespace(f, current, namespace)
62
+ }
63
+ end
64
+
65
+ private
66
+
67
+ def self.write_namespace(f, current, namespace)
68
+ ExtJS::MVC.ui.confirm(" namespacing #{f}")
69
+ gsub_file(f, current, namespace)
70
+ end
71
+
72
+ #find/replace in a file. Stolen/adapted from Rails
73
+ def self.gsub_file(filename, regexp, *args, &block)
74
+ content = File.read(filename).gsub(regexp, *args, &block)
75
+ File.open(filename, 'wb') { |file| file.write(content) }
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,57 @@
1
+ module ExtJS
2
+ module MVC
3
+ module Generator
4
+ class App < Base
5
+
6
+ def initialize(name, namespace=nil)
7
+
8
+ @name = name
9
+ @namespace = namespace || Extlib::Inflection.camelize(name)
10
+ end
11
+
12
+ def generate!
13
+ if File.exists?(@name)
14
+ raise ExtJS::MVC::AppAlreadyExists.new("An app named #{@name} already exists")
15
+ end
16
+ FileUtils.mkdir(@name)
17
+ Dir["#{TEMPLATE_PATH}/app/*"].each do |f|
18
+ FileUtils.cp_r(f, @name)
19
+ end
20
+
21
+ FileUtils.cp_r("#{ExtJS::MVC::ROOT}/js", "#{@name}/vendor")
22
+ FileUtils.mv("#{@name}/vendor/js", "#{@name}/vendor/mvc")
23
+
24
+ show_files
25
+
26
+ # Build assets.
27
+ ExtJS::MVC::BuilderManager.dispatch(:setup, {
28
+ :asset_root => File.expand_path('.', @name)
29
+ })
30
+ end
31
+
32
+ private
33
+
34
+ def notify(f)
35
+ @re ||= Regexp.new("#{@name}\/(.*)")
36
+ ExtJS::MVC.ui.confirm(" create #{f.match(@re)[1]}")
37
+ end
38
+
39
+ def show_files
40
+ Dir["#{@name}/*"].reject {|dir|
41
+ dir.match(/public|vendor/) ? true : false
42
+ }.each do |dir|
43
+ Dir["#{dir}/**/*.*"].each do |f|
44
+ notify(f)
45
+ end
46
+ end
47
+ Dir["#{@name}/vendor/*"].each do |f|
48
+ notify(f)
49
+ end
50
+ Dir["#{@name}/public/*"].each do |f|
51
+ notify(f)
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,53 @@
1
+ module ExtJS
2
+ module MVC
3
+ module Generator
4
+ class Base
5
+
6
+ TEMPLATE_PATH = "#{File.dirname(__FILE__)}/templates"
7
+
8
+ def initialize *args
9
+ @gsubs ||= {}
10
+ @gsubs['namespace'] = ExtJS::MVC.environment['namespace']
11
+ end
12
+
13
+ protected
14
+ def ensure_directories_present! *args
15
+ args.each do |a|
16
+ Dir.mkdir(a) unless File.exists?(a)
17
+ end
18
+ end
19
+
20
+ def ensure_no_overwrite! *args
21
+ args.each do |a|
22
+ if File.exists?(a) && !ARGV.include?("--force")
23
+ raise ExtJS::MVC::FileExists.new("File already exists: #{a}")
24
+ end
25
+ end
26
+ end
27
+
28
+ def template(template_filename, destination_filename)
29
+ #write the file
30
+ File.open(destination_filename, 'w') {|f| f.puts(render_template(template_filename))}
31
+
32
+ ExtJS::MVC.ui.confirm(" Created #{destination_filename}")
33
+ end
34
+
35
+ def render_template(template_filename, gsubs = @gsubs)
36
+ #grab the template file text
37
+ template_text = IO.read("#{TEMPLATE_PATH}/#{template_filename}")
38
+
39
+ #translate the template file text
40
+ gsubs.each_pair do |key, value|
41
+ template_text.gsub!(Regexp.new("<%= @#{key} %>"), value)
42
+ end
43
+
44
+ template_text
45
+ end
46
+
47
+ def include_script html_filename, script_filename, dom_id
48
+
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,41 @@
1
+ module ExtJS
2
+ module MVC
3
+ module Generator
4
+ class Controller < Base
5
+ def initialize(name, actions = [])
6
+ super
7
+
8
+ @name = name
9
+ @actions = actions
10
+ @package = name.downcase
11
+
12
+ @gsubs.merge!({
13
+ 'controller_name' => "#{name.capitalize}Controller",
14
+ 'short_name' => @package,
15
+ 'actions' => generate_actions
16
+ })
17
+
18
+ @controller_filename = "app/controllers/#{@gsubs['controller_name']}.js"
19
+ end
20
+
21
+ def generate!
22
+ ensure_no_overwrite! @controller_filename
23
+ ensure_directories_present! "app", "app/controllers"
24
+
25
+ template "Controller.js", @controller_filename
26
+
27
+ generate_views!
28
+ end
29
+
30
+ private
31
+ def generate_actions
32
+ @actions.collect {|act| render_template("_Action.js", {'action_name' => act})}.join("")
33
+ end
34
+
35
+ def generate_views!
36
+ @actions.each {|a| View.new(@package, a).generate!}
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,41 @@
1
+ module ExtJS
2
+ module MVC
3
+ module Generator
4
+ class Model < Base
5
+ def initialize(name, fields = [])
6
+ super
7
+
8
+ @fields = fields
9
+
10
+ @gsubs['name'] = name.capitalize
11
+ @gsubs['model_name'] = name
12
+ @gsubs['inst_name'] = name.downcase
13
+ @gsubs['fields'] = fields.collect {|f| field_template(f[0], f[1])}.join(",\n")
14
+
15
+ @model_filename = "app/models/#{@gsubs['name']}.js"
16
+ @spec_filename = "spec/models/#{@gsubs['name']}.spec.js"
17
+ end
18
+
19
+ def generate!
20
+ ensure_no_overwrite! @model_filename, @spec_filename
21
+
22
+ ensure_directories_present! "app", "app/models"
23
+ ensure_directories_present! "spec", "spec/models"
24
+
25
+ template "Model.js", @model_filename
26
+ template "ModelSpec.js", @spec_filename
27
+ end
28
+
29
+ private
30
+ def field_template(name, type)
31
+ padding = longest_field_length - name.length
32
+ " {name: '#{name}', #{" " * padding}type: '#{type}'}"
33
+ end
34
+
35
+ def longest_field_length
36
+ @fields.collect {|f| f[0].length}.max
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,17 @@
1
+ module ExtJS
2
+ module MVC
3
+ module Generator
4
+ class Scaffold < Base
5
+ def initialize(name, fields = [])
6
+ super
7
+ @fields = fields
8
+ @name = name
9
+ end
10
+
11
+ def generate!
12
+ Model.new(@name, @fields).generate!
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @class <%= @namespace %>.controllers.<%= @controller_name %>
3
+ * @extends ExtMVC.Controller
4
+ */
5
+ <%= @namespace %>.controllers.<%= @controller_name %> = Ext.extend(ExtMVC.Controller, {
6
+ constructor: function() {
7
+ //super
8
+ <%= @namespace %>.controllers.<%= @controller_name %>.superclass.constructor.call(this, {
9
+ viewsPackage: <%= @namespace %>.views.<%= @short_name %>
10
+ });
11
+ <%= @actions %>
12
+ }
13
+ });
14
+
15
+ ExtMVC.OS.getOS().registerController('<%= @short_name %>', <%= @namespace %>.controllers.<%= @controller_name %>);
16
+
17
+ Ext.ns('<%= @namespace %>.views.<%= @short_name %>');
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @class <%= @name %>
3
+ * @extends ExtMVC.model.Base
4
+ */
5
+ ExtMVC.model.define("<%= @name %>", {
6
+ fields: [
7
+ <%= @fields %>
8
+ ]
9
+ });
@@ -0,0 +1,12 @@
1
+ Screw.Unit(function() {
2
+ describe("The <%= @name %> class", function() {
3
+ var <%= @inst_name %>;
4
+ before(function() {
5
+ <%= @inst_name %> = new <%= @namespace %>.models.<%= @name %>({
6
+ //set fields for this model here
7
+ });
8
+ });
9
+
10
+ //create your unit tests here
11
+ });
12
+ });
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @class <%= @namespace %>.views.<%= @view_namespace %>.<%= @name %>
3
+ * @extends Ext.Panel
4
+ * A default generated view
5
+ */
6
+ <%= @namespace %>.views.<%= @view_namespace %>.<%= @name %> = Ext.extend(Ext.Panel, {
7
+
8
+ initComponent: function() {
9
+ Ext.applyIf(this, {
10
+ title: "<%= @name %> Template",
11
+ html: "Find me in <%= @filename %>"
12
+ });
13
+
14
+ <%= @namespace %>.views.<%= @view_namespace %>.<%= @name %>.superclass.initComponent.apply(this, arguments);
15
+ }
16
+ });
@@ -0,0 +1,7 @@
1
+
2
+ /**
3
+ * @action <%= @action_name %>
4
+ */
5
+ this.registerAction('<%= @action_name %>', function() {
6
+ this.renderView('<%= @action_name %>');
7
+ });
@@ -0,0 +1,152 @@
1
+ = ExtJS MVC Base App
2
+
3
+ Ext MVC Application structure for any new MVC application. Structure inspired by Ruby on Rails.
4
+
5
+ == Installation
6
+
7
+ Clone this as the starting point for your apps. Place your cloned directory somewhere apache can serve it, then head to index.html:
8
+
9
+ http://localhost/myDirectory/index.html
10
+
11
+ You should see a default application set up and ready to go.
12
+
13
+ == Prerequisites
14
+
15
+ Most prerequisites are installed for you inside the vendor directory:
16
+
17
+ * vendor/ext - contains a copy of ExtJS v2.2.1 (debug version, production copy by defaults comes off the cachefly CDN)
18
+ * vendor/mvc - contains a copy of the latest stable version of Ext MVC (debug and minified versions)
19
+ * vendor/screw-unit - contains a copy of ScrewUnit, a BDD testing framework for JavaScipt
20
+ * vendor/yui-compressor - contains a copy of the YUI compressor, which is used in the automatic build process
21
+
22
+ Although is is not strictly a prerequisite, you are *strongly* advised to install Ruby and Rubygems as the scripts below will automate a lot of things
23
+ for you and save you a lot of time. If you're running OSX you probably already have these, if you're on Windows it's a very simple install process.
24
+ Take a look at http://rubyonrails.org/download for instructions (just the Ruby and RubyGems sections).
25
+
26
+ If you don't intend to use the Ruby automation scripts, you can safely delete the script, vendor/mvc/scripts and vendor/yui-compressor folders.
27
+
28
+ == Getting Started
29
+
30
+ The only thing you need to change is the namespace your application will be using. Choose a meaningful namespace for your application - e.g. for
31
+ a blog application you might choose BlogApp, or something similar. All of your code will sit under that namespace, like this:
32
+
33
+ * BlogApp.models.Post // reference to a Post model constructor
34
+ * BlogApp.controllers.IndexController // reference to a controller constructor
35
+ * BlogApp.views.posts.New // reference to a view constructor, usually an Ext.Panel subclass
36
+
37
+ It doesn't matter if you don't know what those do yet, the important thing is that you don't pollute the global namespace. The whole of Ext MVC is
38
+ build around this idea.
39
+
40
+ Once you've chosen your namespace, just run the following command:
41
+
42
+ ruby script/setup MyAppNamespace
43
+
44
+ This will update all files with the default namespace ('MyApp') with the namespace you specify.
45
+
46
+ If you can't run the script, you can easily perform the setup yourself - just change the references from the default 'MyApp' namespace to your own
47
+ namespace in the following files:
48
+
49
+ * app/OS.js
50
+ * app/controllers/IndexController.js
51
+ * app/views/index/Index.js
52
+ * config/initialize.js
53
+ * config/settings.yml
54
+
55
+ Just use a simple find/replace all.
56
+
57
+ == Build tools
58
+
59
+ You need to ensure you have Ruby installed to use the build tools, and also the rake and hpricot gems (sudo gem install rake hpricot).
60
+
61
+ Ext MVC will automatically build (concatenate and minify) your javascript and CSS files. Just run the following command from the base directory:
62
+
63
+ ruby script/build all
64
+
65
+ This will inspect the javascript and css include tags inside index.html and compress them into a single JS file and a single CSS file. It will minify
66
+ the javascript if the YUI Compressor is installed in vendor/yui-compressor and create the following files:
67
+
68
+ * public/application-all.js
69
+ * public/application-all-min.js
70
+ * public/stylesheets/application-all.css
71
+
72
+ == Generators:
73
+
74
+ Ext MVC comes with some built-in generators to automate some aspects of application development. Run the generators
75
+ described below from within the main directory of your Ext MVC application.
76
+
77
+ Be sure that you have updated your config/settings.yml file before running these, otherwise everything will be namespaced
78
+ to 'MyApp' (see above).
79
+
80
+ === Model
81
+
82
+ ruby script/generate model User first_name:string last_name:string balance:int is_admin:boolean
83
+
84
+ Will generate the following files:
85
+
86
+ in app/models/User.js:
87
+ /**
88
+ * @class MyApp.models.MyModel
89
+ * @extends ExtMVC.Model
90
+ */
91
+ ExtMVC.Model.define("MyApp.models.User", {
92
+ modelName: 'user',
93
+ fields: [
94
+ {name: 'first_name', type: 'string'},
95
+ {name: 'last_name', type: 'string'},
96
+ {name: 'balance', type: 'int'},
97
+ {name: 'is_admin', type: 'boolean'}
98
+ ]
99
+ });
100
+
101
+ in spec/models/User.spec.js:
102
+ Screw.Unit(function() {
103
+ describe("The User class", function() {
104
+ var user;
105
+ before(function() {
106
+ user = new MyApp.models.User({
107
+ //set fields for this model here
108
+ });
109
+ });
110
+
111
+ //create your unit tests here
112
+ });
113
+ });
114
+
115
+ It will also add the following line to your index.html file:
116
+
117
+ <script type="text/javascript" src="app/models/User.js"></script>
118
+
119
+ And the following to your spec/index.html file:
120
+
121
+ <script type="text/javascript" src="../app/models/User.js"></script>
122
+ <script type="text/javascript" src="models/User.spec.js"></script>
123
+
124
+
125
+ == Deployment
126
+
127
+ Once you've built your app, upload only the 'public' folder to your web server. Nothing else is required to run the app.
128
+
129
+ == Directory Structure:
130
+
131
+ * app - a directory to contain your models, views and controllers
132
+ * app/controllers - contains all of your controllers
133
+ * app/models - contains all modesl
134
+ * app/views - contains all view files, usually in subdirectories (e.g. app/views/users/Index.js)
135
+ * config - contains application configuration files (see below)
136
+ * lib - contains any library files which are not suited to being plugins
137
+ * public - the directory you will set as document root on your web server. Place any public-facing assets in here. Note that all javascript and stylesheet files will be concatenated automatically into here when you deploy, so these can exist outside of this folder. Images and other assets will need to be placed here though.
138
+ * script - contains scripts to automate site build and minification
139
+ * spec - a directory to place your unit tests or specs
140
+ * vendor - holds any third-party code
141
+ * vendor/ext - contains the required version of ExtJS. ExtJS 2.2 comes pre-installed here, with the Ext adapter.
142
+ * vendor/mvc - contains the required version of Ext MVC. Most recent stable version installed by default. Obtain latest version from http://github.com/extmvc/extmvc/tree
143
+ * vendor/plugins - contains any MVC-compatible plugins (such as viewport builders, model extensions etc)
144
+
145
+ == Important Files:
146
+
147
+ * config/routes.js - set up any Ext.History related routing required (see file for help)
148
+ * config/initialize.js - any app-wide config code, such as setting up location of s.gif, booting your app, etc
149
+ * config/database.js - define which data adapter your app uses (RESTful adapter, Gears adapter, your own concoction etc)
150
+
151
+ * index.html - Development version of the site, including one file at a time and using ext-all-debug
152
+ * public/index.html - Production version of the site referencing concatenated and minified files
@@ -0,0 +1,64 @@
1
+ /**
2
+ * @class MyApp.App
3
+ * @extends ExtMVC.App
4
+ * The MyApp application.
5
+ */
6
+
7
+ ExtMVC.App.define({
8
+ name : "MyApp",
9
+
10
+ /**
11
+ * Sets up the application's Viewport
12
+ */
13
+ launch: function() {
14
+
15
+ Ext.QuickTips.init();
16
+
17
+ this.menu = ExtMVC.buildView('layout', 'menu', {
18
+ region : 'west',
19
+ split: true,
20
+ width : 240,
21
+ listeners: {
22
+ scope: this,
23
+ click: function(node) {
24
+ var attrs = node.attributes;
25
+
26
+ if (attrs.controller != undefined) {
27
+ ExtMVC.dispatch({controller: attrs.controller, action: attrs.action});
28
+ }
29
+ }
30
+ }
31
+ });
32
+
33
+ /**
34
+ * @property main
35
+ * @type Ext.Panel
36
+ * A container into which views are rendered
37
+ */
38
+ this.main = new Ext.TabPanel({
39
+ region: 'center',
40
+ border: false,
41
+ cls : 'mainPanel',
42
+ activeTab: 0
43
+ });
44
+
45
+ this.viewport = new Ext.Viewport({
46
+ layout: 'border',
47
+ items: [{
48
+ xtype: 'box',
49
+ region: 'north',
50
+ height: 30
51
+ },this.menu, this.main
52
+ ]
53
+ });
54
+
55
+ this.fireEvent('launched');
56
+
57
+ ExtMVC.dispatch('home', 'index');
58
+
59
+ Ext.get('loading').remove();
60
+ Ext.get('loading-mask').fadeOut({remove:true});
61
+ }
62
+ });
63
+
64
+