chaplin-on-rails 0.7.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.md +42 -0
  3. data/Rakefile +38 -0
  4. data/lib/chaplin-on-rails.rb +2 -0
  5. data/lib/chaplin-on-rails/engine.rb +6 -0
  6. data/lib/chaplin-on-rails/version.rb +3 -0
  7. data/lib/generators/chaplin/helpers.rb +94 -0
  8. data/lib/generators/chaplin/install/install_generator.rb +68 -0
  9. data/lib/generators/chaplin/install/templates/app_template.js.coffee +65 -0
  10. data/lib/generators/chaplin/install/templates/application.js.coffee +13 -0
  11. data/lib/generators/chaplin/install/templates/javascripts/controllers/base/controller.js.coffee +8 -0
  12. data/lib/generators/chaplin/install/templates/javascripts/lib/support.js.coffee +19 -0
  13. data/lib/generators/chaplin/install/templates/javascripts/lib/utils.js.coffee +18 -0
  14. data/lib/generators/chaplin/install/templates/javascripts/lib/view_helper.js.coffee +16 -0
  15. data/lib/generators/chaplin/install/templates/javascripts/models/base/collection.js.coffee +9 -0
  16. data/lib/generators/chaplin/install/templates/javascripts/models/base/model.js.coffee +9 -0
  17. data/lib/generators/chaplin/install/templates/javascripts/routes.js.coffee +9 -0
  18. data/lib/generators/chaplin/install/templates/javascripts/views/base/collection_view.coffee +11 -0
  19. data/lib/generators/chaplin/install/templates/javascripts/views/base/view.coffee +15 -0
  20. data/lib/generators/chaplin/install/templates/javascripts/views/layout.js.coffee +8 -0
  21. data/lib/generators/chaplin/install/templates/requirejs.yml +6 -0
  22. data/test/chaplin-on-rails_test.rb +19 -0
  23. data/test/dummy/README.rdoc +261 -0
  24. data/test/dummy/Rakefile +7 -0
  25. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  26. data/test/dummy/app/controllers/application_controller.rb +3 -0
  27. data/test/dummy/app/controllers/home_controller.rb +5 -0
  28. data/test/dummy/app/helpers/application_helper.rb +2 -0
  29. data/test/dummy/app/helpers/home_helper.rb +2 -0
  30. data/test/dummy/app/views/home/index.html.erb +1 -0
  31. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  32. data/test/dummy/config.ru +4 -0
  33. data/test/dummy/config/application.rb +59 -0
  34. data/test/dummy/config/boot.rb +10 -0
  35. data/test/dummy/config/database.yml +25 -0
  36. data/test/dummy/config/environment.rb +5 -0
  37. data/test/dummy/config/environments/development.rb +37 -0
  38. data/test/dummy/config/environments/production.rb +67 -0
  39. data/test/dummy/config/environments/test.rb +37 -0
  40. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  41. data/test/dummy/config/initializers/inflections.rb +15 -0
  42. data/test/dummy/config/initializers/mime_types.rb +5 -0
  43. data/test/dummy/config/initializers/secret_token.rb +7 -0
  44. data/test/dummy/config/initializers/session_store.rb +8 -0
  45. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  46. data/test/dummy/config/locales/en.yml +5 -0
  47. data/test/dummy/config/routes.rb +58 -0
  48. data/test/dummy/db/development.sqlite3 +0 -0
  49. data/test/dummy/db/test.sqlite3 +0 -0
  50. data/test/dummy/log/development.log +186 -0
  51. data/test/dummy/log/test.log +35 -0
  52. data/test/dummy/public/404.html +26 -0
  53. data/test/dummy/public/422.html +26 -0
  54. data/test/dummy/public/500.html +25 -0
  55. data/test/dummy/public/favicon.ico +0 -0
  56. data/test/dummy/script/rails +6 -0
  57. data/test/dummy/tmp/cache/assets/C75/D70/sprockets%2F1781f0919424c1d3014e066757a81eaa +0 -0
  58. data/test/dummy/tmp/cache/assets/C80/150/sprockets%2F0d3881005b0646df783d5c24683d34f5 +0 -0
  59. data/test/dummy/tmp/cache/assets/C89/4B0/sprockets%2F1f6245087eeb4c854a03a4644c964579 +0 -0
  60. data/test/dummy/tmp/cache/assets/C8D/980/sprockets%2F7184f95c8e290cbc2451767559f01d08 +0 -0
  61. data/test/dummy/tmp/cache/assets/CA8/130/sprockets%2F695a47c24c7804e27afc2208426ae133 +0 -0
  62. data/test/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
  63. data/test/dummy/tmp/cache/assets/CDE/EC0/sprockets%2F32bce1758d7525013970c7bb7d77aa28 +0 -0
  64. data/test/dummy/tmp/cache/assets/CEB/750/sprockets%2F72f4d157b237c37ed75f49bd217824c7 +0 -0
  65. data/test/dummy/tmp/cache/assets/CF6/290/sprockets%2F95f8b25659fb7a430d68b27a5f72f666 +0 -0
  66. data/test/dummy/tmp/cache/assets/CF9/7C0/sprockets%2F40fc2f3d2a468a00e463f1d313cb1683 +0 -0
  67. data/test/dummy/tmp/cache/assets/D08/A30/sprockets%2F1310a2826dcae357ba9f383e86b638a1 +0 -0
  68. data/test/dummy/tmp/cache/assets/D09/100/sprockets%2F4dc073204163e0850bf7fcb55ff8b552 +0 -0
  69. data/test/dummy/tmp/cache/assets/D0A/A40/sprockets%2F09e4e8ba330b24f9f87a63a910d422f3 +0 -0
  70. data/test/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
  71. data/test/dummy/tmp/cache/assets/D38/B80/sprockets%2F42c6d981cbd6ae6061c7088a2321a8ed +0 -0
  72. data/test/dummy/tmp/cache/assets/D3E/070/sprockets%2F45f1913b6d3645a3d166ff4ff250e4cc +0 -0
  73. data/test/dummy/tmp/cache/assets/D4E/D00/sprockets%2F1a6846f0a837ae2524e2f9ec89e6ef43 +0 -0
  74. data/test/dummy/tmp/cache/assets/D57/BC0/sprockets%2F50db33dbb1258913cb2fbd562ab1294b +0 -0
  75. data/test/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
  76. data/test/dummy/tmp/cache/assets/D63/C90/sprockets%2Fb70150e50cbcbc59c55ffb3c53a35575 +0 -0
  77. data/test/dummy/tmp/cache/assets/D6F/C70/sprockets%2F667a4890bf4c03f50b452d1db278fcfe +0 -0
  78. data/test/dummy/tmp/cache/assets/D79/470/sprockets%2F1cb96b862f7c7497af494aa19d0cbd55 +0 -0
  79. data/test/dummy/tmp/cache/assets/D7A/930/sprockets%2F3964cc67ad46beb69c444bb51f486e2f +0 -0
  80. data/test/dummy/tmp/cache/assets/D8B/B40/sprockets%2F11b945abcf62b02fcfb34f52f6aa1481 +0 -0
  81. data/test/dummy/tmp/cache/assets/D92/990/sprockets%2F4b34320d2682dc0fd9b107f3ef2cae7d +0 -0
  82. data/test/dummy/tmp/cache/assets/D98/8B0/sprockets%2Fedbef6e0d0a4742346cf479f2c522eb0 +0 -0
  83. data/test/dummy/tmp/cache/assets/DC8/010/sprockets%2F34cce381cfe1aa4be1ca560f118dd998 +0 -0
  84. data/test/dummy/tmp/cache/assets/DCD/ED0/sprockets%2F77ca908f86a8be3506de6fe60b1e0baa +0 -0
  85. data/test/dummy/tmp/cache/assets/DCE/890/sprockets%2Fd54185fb144acd9d1d15ed0e4ebf9f44 +0 -0
  86. data/test/dummy/tmp/cache/assets/DCE/D00/sprockets%2Fed31b7ea3cfb14d43a87c89deb0390f7 +0 -0
  87. data/test/dummy/tmp/cache/assets/DCF/610/sprockets%2Fda58bc8db5dd9cb124a85c507d591fd2 +0 -0
  88. data/test/dummy/tmp/cache/assets/E11/4E0/sprockets%2F86e145a39f85cceeaffdff91ebb61449 +0 -0
  89. data/test/test_helper.rb +7 -0
  90. data/vendor/assets/javascripts/backbone.js +1497 -0
  91. data/vendor/assets/javascripts/chaplin.js.coffee +2377 -0
  92. data/vendor/assets/javascripts/underscore.js +1222 -0
  93. metadata +292 -0
@@ -0,0 +1,20 @@
1
+ Copyright 2013 Mikhail Di
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,42 @@
1
+ # ChaplinOnRails
2
+
3
+ Gem for using [Chaplin.js](https://github.com/chaplinjs/chaplin) with Rails asset pipeline, based on
4
+ [chaplin-rails](https://github.com/chaplinjs/chaplin-rails) boilerplate project.
5
+
6
+ Since Chaplin requires module system this gem has
7
+ [requirejs-rails](https://github.com/jwhitley/requirejs-rails) gem
8
+ in dependecy. Those, you're forced to use `requirejs` for your project :)
9
+
10
+ Gem already comes with `underscore.js` and `backbone.js`.
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ gem 'chaplin-on-rails', git: 'git://github.com/eicca/chaplin-on-rails.git'
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ ## Usage
23
+
24
+ Run
25
+
26
+ rails g chaplin:install
27
+
28
+ It should create basic application structure with some basic files.
29
+ To learn more about this see
30
+ [chaplin-rails](https://github.com/chaplinjs/chaplin-rails).
31
+
32
+ This gem generates new `application.js.coffee` for you, so you should
33
+ migrate your old `application.js` to `requirejs` config file and remove
34
+ `application.js` file.
35
+
36
+ Also, there might be a problem with replacing `requirejs_include_tag`.
37
+ Just follow for generator's output instructions.
38
+
39
+ ## TODO
40
+
41
+ 1. Write tests for install generator.
42
+ 2. Write generators for scaffold/resource/controller/model.
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'ChaplinOnRails'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+
24
+
25
+
26
+ Bundler::GemHelper.install_tasks
27
+
28
+ require 'rake/testtask'
29
+
30
+ Rake::TestTask.new(:test) do |t|
31
+ t.libs << 'lib'
32
+ t.libs << 'test'
33
+ t.pattern = 'test/**/*_test.rb'
34
+ t.verbose = false
35
+ end
36
+
37
+
38
+ task :default => :test
@@ -0,0 +1,2 @@
1
+ require "chaplin-on-rails/engine"
2
+ require "chaplin-on-rails/version"
@@ -0,0 +1,6 @@
1
+ require 'requirejs-rails'
2
+
3
+ module ChaplinOnRails
4
+ class Engine < Rails::Engine
5
+ end
6
+ end
@@ -0,0 +1,3 @@
1
+ module ChaplinOnRails
2
+ VERSION = "0.7.0.1"
3
+ end
@@ -0,0 +1,94 @@
1
+ module Chaplin
2
+ module Generators
3
+ module Helpers
4
+
5
+ def asset_path
6
+ File.join('app', 'assets')
7
+ end
8
+
9
+ def javascript_path
10
+ File.join(asset_path, 'javascripts')
11
+ end
12
+
13
+ def model_path
14
+ File.join(javascript_path, "models")
15
+ end
16
+
17
+ def view_path
18
+ File.join(javascript_path, "views")
19
+ end
20
+
21
+ def controller_path
22
+ File.join(javascript_path, "controllers")
23
+ end
24
+
25
+ def lib_path
26
+ File.join(javascript_path, "lib")
27
+ end
28
+
29
+ def base_path(path)
30
+ File.join(path, 'base')
31
+ end
32
+
33
+ def template_path
34
+ File.join(asset_path, "templates")
35
+ end
36
+
37
+ def singular_file_name
38
+ "#{file_name.singularize}#{@ext}"
39
+ end
40
+
41
+ def plural_file_name
42
+ "#{file_name.pluralize}#{@ext}"
43
+ end
44
+
45
+ def router_file_name
46
+ "#{file_name.pluralize}_router#{@ext}"
47
+ end
48
+
49
+ def view_file_name
50
+ "#{file_name.pluralize}_index#{@ext}"
51
+ end
52
+
53
+ def model_namespace
54
+ [app_name, "Models", file_name.singularize.camelize].join(".")
55
+ end
56
+
57
+ def collection_namespace
58
+ [app_name, "Collections", file_name.pluralize.camelize].join(".")
59
+ end
60
+
61
+ def router_namespace
62
+ [app_name, "Routers", file_name.pluralize.camelize].join(".")
63
+ end
64
+
65
+ def view_namespace
66
+ [app_name, "Views", "#{file_name.pluralize.camelize}Index"].join(".")
67
+ end
68
+
69
+ def template_namespace
70
+ File.join(file_path.pluralize, "index")
71
+ end
72
+
73
+ def app_name
74
+ rails_app_name.camelize
75
+ end
76
+
77
+ def app_filename
78
+ rails_app_name.underscore
79
+ end
80
+
81
+ def rails_app_name
82
+ Rails.application.class.name.split('::').first
83
+ end
84
+
85
+ def layout_path
86
+ Dir['app/views/layouts/application*'].first
87
+ end
88
+
89
+ def display(output, color = :green)
90
+ say(" - #{output}", color)
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,68 @@
1
+ require 'generators/chaplin/helpers'
2
+
3
+ module Chaplin
4
+ module Generators
5
+ class InstallGenerator < Rails::Generators::Base
6
+ include Chaplin::Generators::Helpers
7
+
8
+ source_root File.expand_path("../templates", __FILE__)
9
+
10
+ desc "Generates a Chaplin.js skeleton directory structure and manifest"
11
+
12
+ # TODO currently only coffee works
13
+ #class_option :javascript,
14
+ #type: :boolean,
15
+ #aliases: "-j",
16
+ #default: false,
17
+ #desc: "Generate JavaScript"
18
+
19
+ def copy_app_boilerplate
20
+ # it should remove empty directories during 'destroy' command
21
+ %w(controllers lib models views).each do |dir_name|
22
+ empty_directory File.join(javascript_path, dir_name)
23
+ end
24
+
25
+ # copy all /javascripts directory
26
+ directory 'javascripts', javascript_path
27
+
28
+ # create empty 'assets/templates' directory
29
+ empty_directory template_path
30
+ end
31
+
32
+ def generate_app_files
33
+ template "application.js.coffee", "#{javascript_path}/application.js.coffee"
34
+ template "app_template.js.coffee", "#{javascript_path}/#{app_filename}.js.coffee"
35
+ end
36
+
37
+ def apply_requirejs
38
+ # copy config file
39
+ copy_file 'requirejs.yml', 'config/requirejs.yml'
40
+
41
+ # check if we can find layout file
42
+ # TODO doesn't work during 'destroy' command
43
+ if layout_path
44
+ # inject requirejs tag
45
+ unless gsub_file(layout_path, /javascript_include_tag/, 'requirejs_include_tag')
46
+ display "Can't find a javascript_include_tag in '#{layout_path}'!"
47
+ display "You must add 'requirejs_include_tag' instead of 'javascript_include_tag'"
48
+ display "in your layout(s)."
49
+ end
50
+ else
51
+ display "Can't find a layout to inject requirejs tag!"
52
+ display "You must add 'requirejs_include_tag' instead of 'javascript_include_tag'"
53
+ display "in your layout(s)."
54
+ end
55
+ end
56
+
57
+
58
+ def post_install_messages
59
+ if File.exists?("#{javascript_path}/application.js")
60
+ display "You have 'application.js' file in your 'assets/' folder."
61
+ display "You should migrate all dependencies to the 'requirejs.yml' config file"
62
+ display "and remove 'application.js file."
63
+ end
64
+ end
65
+
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,65 @@
1
+ define [
2
+ 'chaplin'
3
+ 'views/layout'
4
+ 'routes'
5
+ # Require base controllers manually because
6
+ # they aren’t compiled individually
7
+ # 'controllers/my_controller'
8
+ ], (Chaplin, Layout, routes) ->
9
+ 'use strict'
10
+
11
+ # The application object
12
+ # Choose a meaningful name for your application
13
+ class <%= app_name %> extends Chaplin.Application
14
+
15
+ # Set your application name here so the document title is set to
16
+ # “Controller title – Site title” (see Layout#adjustTitle)
17
+ title: '<%= rails_app_name %>'
18
+
19
+ initialize: ->
20
+ super
21
+
22
+ # Initialize core components
23
+ @initDispatcher()
24
+ @initLayout()
25
+ @initMediator()
26
+
27
+ # Application-specific scaffold
28
+ @initControllers()
29
+
30
+ # Register all routes and start routing
31
+ @initRouter routes
32
+ # You might pass Router/History options as the second parameter.
33
+ # Chaplin enables pushState per default and Backbone uses / as
34
+ # the root per default. You might change that in the options
35
+ # if necessary:
36
+ # @initRouter routes, pushState: false, root: '/subdir/'
37
+
38
+ # Freeze the application instance to prevent further changes
39
+ Object.freeze? this
40
+
41
+ # Override standard layout initializer
42
+ # ------------------------------------
43
+ initLayout: ->
44
+ # Use an application-specific Layout class. Currently this adds
45
+ # no features to the standard Chaplin Layout, it’s an empty placeholder.
46
+ @layout = new Layout {@title}
47
+
48
+ # Instantiate common controllers
49
+ # ------------------------------
50
+ initControllers: ->
51
+ # These controllers are active during the whole application runtime.
52
+ # You don’t need to instantiate all controllers here, only special
53
+ # controllers which do not to respond to routes. They may govern models
54
+ # and views which are needed the whole time, for example header, footer
55
+ # or navigation views.
56
+ # e.g. new NavigationController()
57
+
58
+ # Create additional mediator properties
59
+ # -------------------------------------
60
+ initMediator: ->
61
+ # Create a user property
62
+ Chaplin.mediator.user = null
63
+ # Add additional application-specific properties and methods
64
+ # Seal the mediator
65
+ Chaplin.mediator.seal()
@@ -0,0 +1,13 @@
1
+ #
2
+ # add '= require hamlcoffee' for hamlcoffee support
3
+ #
4
+ #= require_tree ../templates
5
+
6
+ # Bootstrap the application
7
+ require [
8
+ '<%= app_filename %>'
9
+ ], (<%= app_name %>) ->
10
+ 'use strict'
11
+
12
+ app = new <%= app_name %>()
13
+ app.initialize()
@@ -0,0 +1,8 @@
1
+ define [
2
+ 'chaplin'
3
+ ], (Chaplin) ->
4
+ 'use strict'
5
+
6
+ class Controller extends Chaplin.Controller
7
+
8
+ # Place your application-specific controller features here
@@ -0,0 +1,19 @@
1
+ define [
2
+ 'underscore'
3
+ 'lib/utils'
4
+ 'chaplin'
5
+ ], (_, utils, Chaplin) ->
6
+
7
+ # Application-specific feature detection
8
+ # --------------------------------------
9
+
10
+ # Delegate to Chaplin’s support module
11
+ support = utils.beget Chaplin.support
12
+
13
+ # Add additional application-specific properties and methods
14
+
15
+ # _(support).extend
16
+ # someProperty: 'foo'
17
+ # someMethod: ->
18
+
19
+ support
@@ -0,0 +1,18 @@
1
+ define [
2
+ 'underscore'
3
+ 'chaplin'
4
+ ], (_, Chaplin) ->
5
+
6
+ # Application-specific utilities
7
+ # ------------------------------
8
+
9
+ # Delegate to Chaplin’s utils module
10
+ utils = Chaplin.utils.beget Chaplin.utils
11
+
12
+ # Add additional application-specific properties and methods
13
+
14
+ # _(utils).extend
15
+ # someProperty: 'foo'
16
+ # someMethod: ->
17
+
18
+ utils
@@ -0,0 +1,16 @@
1
+ define [
2
+ 'chaplin'
3
+ 'lib/utils'
4
+ ], (Handlebars, Chaplin, utils) ->
5
+ 'use strict'
6
+
7
+ # View helpers (HAML Coffee in this case)
8
+ # ---------------------------------------
9
+
10
+ HAML.globals = ->
11
+ {
12
+ #someProperty: 'foo'
13
+ #someMethod: ->
14
+ }
15
+
16
+ null
@@ -0,0 +1,9 @@
1
+ define [
2
+ 'chaplin'
3
+ ], (Chaplin) ->
4
+
5
+ class Collection extends Chaplin.Collection
6
+ # Mixin a synchronization state machine
7
+ # _(@prototype).extend Chaplin.SyncMachine
8
+
9
+ # Place your application-specific collection features here
@@ -0,0 +1,9 @@
1
+ define [
2
+ 'chaplin'
3
+ ], (Chaplin) ->
4
+
5
+ class Model extends Chaplin.Model
6
+ # Mixin a synchronization state machine
7
+ # _(@prototype).extend Chaplin.SyncMachine
8
+
9
+ # Place your application-specific model features here