marionette_dust 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.rspec +1 -0
  4. data/.travis.yml +5 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +114 -0
  8. data/Rakefile +5 -0
  9. data/lib/generators/marionette_dust/common/templates/app.js +10 -0
  10. data/lib/generators/marionette_dust/common/templates/controller.js +3 -0
  11. data/lib/generators/marionette_dust/common/templates/entity.js +9 -0
  12. data/lib/generators/marionette_dust/common/templates/template.jst.dust +1 -0
  13. data/lib/generators/marionette_dust/common/templates/view.js +5 -0
  14. data/lib/generators/marionette_dust/helpers.rb +71 -0
  15. data/lib/generators/marionette_dust/install/install_generator.rb +58 -0
  16. data/lib/generators/marionette_dust/install/templates/app.js +20 -0
  17. data/lib/generators/marionette_dust/install/templates/app.js.coffee +16 -0
  18. data/lib/generators/marionette_dust/scaffold/scaffold_generator.rb +64 -0
  19. data/lib/generators/marionette_dust/submodule/submodule_generator.rb +52 -0
  20. data/lib/marionette_dust/engine.rb +3 -0
  21. data/lib/marionette_dust/version.rb +3 -0
  22. data/lib/marionette_dust.rb +6 -0
  23. data/marionette_dust.gemspec +23 -0
  24. data/vendor/assets/javascripts/marionette_dust/backbone.js +1581 -0
  25. data/vendor/assets/javascripts/marionette_dust/backbone.marionette.js +2385 -0
  26. data/vendor/assets/javascripts/marionette_dust/dust-full-2.1.0.js +3759 -0
  27. data/vendor/assets/javascripts/marionette_dust/dust-helpers-1.1.1.js +523 -0
  28. data/vendor/assets/javascripts/marionette_dust/index.js +7 -0
  29. data/vendor/assets/javascripts/marionette_dust/marionette_renderer.js +11 -0
  30. data/vendor/assets/javascripts/marionette_dust/template_loader.js +13 -0
  31. data/vendor/assets/javascripts/marionette_dust/underscore.js +1276 -0
  32. metadata +103 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 079cde9464f0f39843701f532fa51ff16f8fd40e
4
+ data.tar.gz: 074ca9812423cd91a3985db801ff8ec1fdeef838
5
+ SHA512:
6
+ metadata.gz: 184bab9d0b4be2889f44ef27009b9c583dd64f33aafa6ddb139b887106d604e28f8ee85520dca7353dcc831cae991c230c4846a484aa8ac7283441470c113a51
7
+ data.tar.gz: 5c5024395e17239a7ce9501d8cd444e7cdda7b6eae29edb9365988511e51aee2c4fd320d4b2f56850a545687a08e8669f115fa8538426154cc82f5520ee3c954
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in marionette_dust.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 RobertoDip
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,114 @@
1
+ [![Dependency Status][GM img]][Gemnasium]
2
+ [![Build Status][BS img]][Build Status]
3
+ [![Code Climate][CC img]][Code Climate]
4
+
5
+ MarionetteDust - Rails
6
+ =======
7
+
8
+ Provides full integration between [Marionette.js][1] (and dependencies), [Dust.js][2] and the Asset Pipeline, also includes generators for a typical marionette application.
9
+
10
+ Installation
11
+ -------
12
+
13
+
14
+ Add marionette_dust in your gemfile:
15
+
16
+ ```ruby
17
+ gem 'marionette_dust'
18
+ ```
19
+ Download and install by running:
20
+
21
+ ```
22
+ $ bundle install
23
+ ```
24
+
25
+ Initialize your app with:
26
+
27
+ ```
28
+ $ rails generate marionette_dust:install
29
+ ```
30
+
31
+ This adds `//= require marionette_dust` in your application.js manifest and generates the basic scaffold for your marionette application:
32
+
33
+ ```
34
+ app/
35
+ └── assets/
36
+ └── javascripts/
37
+ ├── apps/
38
+ ├── entities/
39
+ └── app.js
40
+ ```
41
+
42
+ Generators
43
+ -------
44
+ All generators are based on [marionette modules][3], the original idea is described in the exellent book [Backbone.Marionette.js: A Gentle Introduction][4], and the all credits go to [BackboneRails.com][5]
45
+
46
+ - **Scaffold**
47
+
48
+ Generates a scaffold for a sub-app, under apps folder, running:
49
+
50
+ ```
51
+ $ rails generate marionette_dust:scaffold Foo
52
+ ```
53
+
54
+ will generate:
55
+ ```
56
+ app/
57
+ └── assets/
58
+ └── javascripts/
59
+ ├── apps/
60
+ | └── foo/
61
+ | └── foo_app.js
62
+ └── entities/
63
+ └── foo.js
64
+ ```
65
+
66
+ - **Submodule**
67
+
68
+ Generates a submodule under an existent app (previously generated with the Scaffold generator), running:
69
+
70
+ ```
71
+ $ rails generate marionette_dust:submodule bar --parent foo
72
+ ```
73
+
74
+ will generate:
75
+ ```
76
+ app/
77
+ └── assets/
78
+ └── javascripts/
79
+ ├── apps/
80
+ | └── foo/
81
+ | ├── bar/
82
+ | ├── bar_view.js
83
+ | └── bar_controller.js
84
+ | └── foo_app.js
85
+ └── entities/
86
+ | └── foo.js
87
+ └── templates/
88
+ └── foo/
89
+ └── bar/
90
+ └── bar.jst.dust
91
+ ```
92
+
93
+ Contributing
94
+ -------
95
+
96
+ 1. Fork it
97
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
98
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
99
+ 4. Push to the branch (`git push origin my-new-feature`)
100
+ 5. Create new Pull Request
101
+
102
+ [1]: http://marionettejs.com/
103
+ [2]: http://linkedin.github.io/dustjs/
104
+ [3]: https://github.com/marionettejs/backbone.marionette/blob/master/docs/marionette.application.module.md
105
+ [4]: https://leanpub.com/marionette-gentle-introduction
106
+ [5]: http://www.backbonerails.com/
107
+
108
+ [Build Status]: https://travis-ci.org/RobertoDip/marionette_dust-rails
109
+ [Code Climate]: https://codeclimate.com/github/RobertoDip/marionette_dust-rails
110
+ [Gemnasium]: https://gemnasium.com/RobertoDip/marionette_dust-rails
111
+
112
+ [BS img]: https://travis-ci.org/RobertoDip/marionette_dust-rails.png
113
+ [CC img]: https://codeclimate.com/github/RobertoDip/marionette_dust-rails.png
114
+ [GM img]: https://gemnasium.com/RobertoDip/marionette_dust-rails.png
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ task :default do
4
+ puts "Default task called!"
5
+ end
@@ -0,0 +1,10 @@
1
+ <%= app_name %>.module("<%= sub_app_name %>", function (<%= sub_app_name %>, <%= app_name %>, Backbone, Marionette, $, _) {
2
+ <%= sub_app_name %>.Router = Marionette.AppRouter.extend({
3
+ appRoutes: {}
4
+ });
5
+
6
+ var API = {};
7
+
8
+ <%= app_name %>.on("contacts:list", function () {});
9
+
10
+ });
@@ -0,0 +1,3 @@
1
+ <%= app_name %>.module("<%= file_name.capitalize %>.<%= sub_app_scope %>", function (<%= sub_app_scope %>, <%= app_name %>, Backbone, Marionette, $, _) {
2
+ <%= sub_app_scope %>.Controller = {};
3
+ });
@@ -0,0 +1,9 @@
1
+ <%= app_name %>.module("Entities", function (Entities, <%= app_name %>, Backbone, Marionette, $, _) {
2
+
3
+ Entities.<%= singular_entity_name %> = Backbone.Model.extend({});
4
+
5
+ Entities.<%= plural_entity_name %>Collection = Backbone.Collection.extend({});
6
+
7
+ var API = {};
8
+
9
+ });
@@ -0,0 +1,5 @@
1
+ <%= app_name %>.module("<%= file_name.capitalize %>.<%= sub_app_scope %>", function (<%= sub_app_scope %>, <%= app_name %>, Backbone, Marionette, $, _) {
2
+ <%= sub_app_scope %>.View = Marionette.ItemView.extend({
3
+ template: "templates/<%= @submodule_name %>.jst.dust"
4
+ });
5
+ });
@@ -0,0 +1,71 @@
1
+ module MarionetteDust
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 entities_path
14
+ File.join(javascript_path, "entities")
15
+ end
16
+
17
+ def apps_path
18
+ File.join(javascript_path, "apps")
19
+ end
20
+
21
+ def template_path
22
+ File.join(asset_path, "templates")
23
+ end
24
+
25
+ def singular_file_name
26
+ "#{file_name.singularize}#{@ext}"
27
+ end
28
+
29
+ def plural_file_name
30
+ "#{file_name.pluralize}#{@ext}"
31
+ end
32
+
33
+ def asset_file_name(type)
34
+ "#{@submodule_name.downcase.singularize}_#{type}#{@ext}"
35
+ end
36
+
37
+ def singular_entity_name
38
+ file_name.singularize.camelize
39
+ end
40
+
41
+ def plural_entity_name
42
+ file_name.pluralize.camelize
43
+ end
44
+
45
+ def sub_app_name
46
+ [file_name.pluralize.camelize, "App"].join("")
47
+ end
48
+
49
+ def sub_app_file_name
50
+ [file_name.singularize.downcase, "_app", "#{@ext}"].join("")
51
+ end
52
+
53
+ def sub_app_scope
54
+ @submodule_name.capitalize
55
+ end
56
+
57
+ def app_name
58
+ rails_app_name.camelize
59
+ end
60
+
61
+ def app_filename
62
+ rails_app_name.underscore
63
+ end
64
+
65
+ def rails_app_name
66
+ Rails.application.class.name.split('::').first
67
+ end
68
+
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,58 @@
1
+ require 'generators/marionette_dust/helpers'
2
+
3
+ module MarionetteDust
4
+ module Generators
5
+ class InstallGenerator < Rails::Generators::Base
6
+ include MarionetteDust::Generators::Helpers
7
+
8
+ source_root File.expand_path("../templates", __FILE__)
9
+
10
+ desc "Generates a MarionetteDust.js skeleton directory structure and manifest"
11
+
12
+ class_option :coffeescript,
13
+ type: :boolean,
14
+ aliases: "-c",
15
+ default: false,
16
+ desc: "Generate CoffeeScript files"
17
+
18
+ class_option :manifest,
19
+ type: :string,
20
+ aliases: "-m",
21
+ default: "application.js",
22
+ desc: "Javascript manifest file to modify (or create)"
23
+
24
+ def create_dir_layout
25
+ empty_directory entities_path
26
+ empty_directory apps_path
27
+ end
28
+
29
+ def create_app_file
30
+ coffee = options.coffeescript
31
+ ext = coffee ? ".js.coffee" : ".js"
32
+ template "app#{ext}", "#{javascript_path}/app#{ext}"
33
+ end
34
+
35
+ def inject_required_files
36
+ manifest = File.join(javascript_path, options.manifest)
37
+ libs = %w(marionette_dust)
38
+ paths = %w(../templates ./entities ./apps)
39
+
40
+ out = []
41
+ out << libs.map{ |lib| "//= require #{lib}" }
42
+ out << "//= require #{app_filename}"
43
+ out << paths.map{ |path| "//= require_tree #{path}" }
44
+ out = out.join("\n") + "\n"
45
+
46
+ in_root do
47
+ create_file(manifest) unless File.exists?(manifest)
48
+ if File.open(manifest).read().include?('//= require_tree')
49
+ inject_into_file(manifest, out, before: '//= require_tree')
50
+ else
51
+ append_file(manifest, out)
52
+ end
53
+ end
54
+ end
55
+
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,20 @@
1
+ var <%= app_name %> = new Marionette.Application();
2
+
3
+ <%= app_name %>.addRegions({
4
+ //Add application regions here
5
+ });
6
+
7
+ //Navigate to specific route
8
+ <%= app_name %>.navigate = function (route, options) {
9
+ options || (options = {});
10
+ Backbone.history.navigate(route, options);
11
+ };
12
+
13
+ //Returns current route
14
+ <%= app_name %>.getCurrentRoute = function () {
15
+ return Backbone.history.fragment;
16
+ };
17
+
18
+ <%= app_name %>.on('initialize:after', function () {
19
+ //Things to do after app initialize
20
+ });
@@ -0,0 +1,16 @@
1
+ <%= app_name %> = new Marionette.Application()
2
+
3
+ #Add application regions here
4
+ <%= app_name %>.addRegions {}
5
+
6
+ #Navigate to specific route
7
+ <%= app_name %>.navigate = (route, options) ->
8
+ options or (options = {})
9
+ Backbone.history.navigate route, options
10
+
11
+ #Returns current route
12
+ <%= app_name %>.getCurrentRoute = ->
13
+ Backbone.history.fragment
14
+
15
+ <%= app_name %>.on "initialize:after", ->
16
+ #Things to do after app initialize
@@ -0,0 +1,64 @@
1
+ require 'generators/marionette_dust/helpers'
2
+
3
+ module MarionetteDust
4
+ module Generators
5
+ class ScaffoldGenerator < Rails::Generators::NamedBase
6
+ include MarionetteDust::Generators::Helpers
7
+
8
+ source_root File.expand_path("../../common/templates", __FILE__)
9
+
10
+ desc "Generates a Marionette.js resource scaffold"
11
+
12
+ class_option :coffeescript,
13
+ type: :boolean,
14
+ aliases: "-c",
15
+ default: false,
16
+ desc: "Generate Coffeescript files"
17
+
18
+ class_option :submodule,
19
+ type: :array,
20
+ aliases: "--sub",
21
+ default: "",
22
+ desc: ""
23
+
24
+ def parse_options
25
+ js = options.javascript
26
+ @ext = js ? ".js.coffee" : ".js"
27
+ end
28
+
29
+ def create_marionette_entity
30
+ file = File.join(entities_path, singular_file_name)
31
+ template "entity#{@ext}", file
32
+ end
33
+
34
+ def create_marionette_app
35
+ empty_directory File.join(apps_path, file_name.downcase)
36
+ file = File.join(apps_path, file_name.downcase, sub_app_file_name)
37
+ template "app.js", file
38
+ end
39
+
40
+ def create_subapp
41
+ return if options.submodule.empty?
42
+ for submodule in options.submodule
43
+ @submodule_name = submodule
44
+ empty_directory File.join(apps_path, file_name.downcase, submodule.downcase)
45
+ create_asset("view")
46
+ create_asset("controller")
47
+ create_dust_template
48
+ end
49
+ end
50
+
51
+ protected
52
+ def create_asset(type)
53
+ file = File.join(apps_path, file_name.downcase, @submodule_name.downcase, asset_file_name(type))
54
+ template "#{type}#{@ext}", file
55
+ end
56
+
57
+ def create_dust_template
58
+ empty_directory File.join(template_path, file_name.downcase, @submodule_name.downcase)
59
+ file = File.join(template_path, file_name.downcase, @submodule_name.downcase, "#{@submodule_name.downcase}.jst.dust")
60
+ template "template.jst.dust", file
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,52 @@
1
+ require 'generators/marionette_dust/helpers'
2
+
3
+ module MarionetteDust
4
+ module Generators
5
+ class SubmoduleGenerator < Rails::Generators::NamedBase
6
+ include MarionetteDust::Generators::Helpers
7
+ include Thor::Actions
8
+
9
+ source_root File.expand_path("../../common/templates", __FILE__)
10
+
11
+ desc "Generates a Marionette.js resource scaffold"
12
+
13
+ class_option :coffeescript,
14
+ type: :boolean,
15
+ aliases: "-c",
16
+ default: false,
17
+ desc: "Generate Coffeescript files"
18
+
19
+ class_option :parent,
20
+ type: :string,
21
+ aliases: "-p",
22
+ required: true,
23
+ desc: "Parent app (required)"
24
+
25
+ def parse_options
26
+ js = options.javascript
27
+ @ext = js ? ".js.coffee" : ".js"
28
+ @parent_name = options.parent
29
+ @submodule_name = file_name
30
+ puts "#{@parent_name}"
31
+ end
32
+
33
+ def create_subapp
34
+ create_asset("view")
35
+ create_asset("controller")
36
+ create_dust_template
37
+ end
38
+
39
+ protected
40
+ def create_asset(type)
41
+ file = File.join(apps_path, @parent_name.downcase, file_name, asset_file_name(type))
42
+ template "#{type}#{@ext}", file
43
+ end
44
+
45
+ def create_dust_template
46
+ empty_directory File.join(template_path, @parent_name, @submodule_name)
47
+ file = File.join(template_path, @parent_name, @submodule_name, "#{@submodule_name}.jst.dust")
48
+ template "template.jst.dust", file
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,3 @@
1
+ module MarionetteDust
2
+ class Engine < Rails::Engine; end
3
+ end
@@ -0,0 +1,3 @@
1
+ module MarionetteDust
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,6 @@
1
+ require "marionette_dust/version"
2
+
3
+ module MarionetteDust
4
+
5
+ require "marionette_dust/engine" if defined?(Rails::Engine)
6
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'marionette_dust/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "marionette_dust"
8
+ spec.version = MarionetteDust::VERSION
9
+ spec.authors = ["RobertoDip"]
10
+ spec.email = ["dip.jesusr@gmail.com"]
11
+ spec.description = %q{An easy way to get Marionette.js and Dust.js working together with the asset pipeline}
12
+ spec.summary = %q{Get up Marionette and Dust in seconds}
13
+ spec.homepage = "https://github.com/RobertoDip/marionette_dust-rails"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end