backbone_generator 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rspec +2 -0
  4. data/LICENSE.txt +1 -1
  5. data/README.md +10 -7
  6. data/backbone_generator.gemspec +9 -15
  7. data/bin/backbone_generator +6 -0
  8. data/lib/backbone_generator.rb +13 -1
  9. data/lib/backbone_generator/auxilliary.rb +44 -0
  10. data/lib/backbone_generator/cli.rb +79 -0
  11. data/lib/backbone_generator/generators/collections/collections_generator.rb +35 -0
  12. data/lib/backbone_generator/generators/collections/template/Collection.tt +29 -0
  13. data/lib/backbone_generator/generators/library/library_generator.rb +17 -0
  14. data/lib/backbone_generator/generators/models/models_generator.rb +35 -0
  15. data/lib/backbone_generator/generators/models/template/Model.tt +44 -0
  16. data/lib/backbone_generator/generators/new/new_generator.rb +89 -0
  17. data/lib/backbone_generator/generators/new/template/.gitignore +1 -0
  18. data/lib/backbone_generator/generators/new/template/README.tt +9 -0
  19. data/lib/backbone_generator/generators/new/template/css/main.css +43 -0
  20. data/lib/backbone_generator/generators/new/template/img/backbone.png +0 -0
  21. data/lib/backbone_generator/generators/new/template/index.html +15 -0
  22. data/lib/backbone_generator/generators/new/template/js/libs/backbone/backbone-1.1.0.js +1498 -0
  23. data/lib/backbone_generator/generators/new/template/js/libs/jquery/jquery-2.0.3.min.js +6 -0
  24. data/lib/backbone_generator/generators/new/template/js/libs/requirejs-text/text-2.0.10.js +332 -0
  25. data/lib/backbone_generator/generators/new/template/js/libs/requirejs/require-2.1.9.js +2019 -0
  26. data/lib/backbone_generator/generators/new/template/js/libs/underscore/underscore-1.5.2.js +1226 -0
  27. data/lib/backbone_generator/generators/new/template/js/views/Main.View.tt +39 -0
  28. data/lib/backbone_generator/generators/new/template/main.tt +45 -0
  29. data/lib/backbone_generator/generators/route/route_generator.rb +36 -0
  30. data/lib/backbone_generator/generators/route/template/Routes.tt +27 -0
  31. data/lib/backbone_generator/generators/templates/template/Template.tt +10 -0
  32. data/lib/backbone_generator/generators/templates/templates_generator.rb +35 -0
  33. data/lib/backbone_generator/generators/tests/template/mainview.js +48 -0
  34. data/lib/backbone_generator/generators/tests/tests_generator.rb +17 -0
  35. data/lib/backbone_generator/generators/utilities/template/Utility.tt +28 -0
  36. data/lib/backbone_generator/generators/utilities/utilities_generator.rb +35 -0
  37. data/lib/backbone_generator/generators/views/template/View.tt +50 -0
  38. data/lib/backbone_generator/generators/views/views_generator.rb +36 -0
  39. data/lib/backbone_generator/post_install_message.rb +21 -0
  40. data/lib/backbone_generator/version.rb +1 -1
  41. data/spec/backbone_generator/post_install_message.rb +20 -0
  42. data/spec/backbone_generator/version.rb +3 -0
  43. data/spec/backbone_generator_spec.rb +5 -0
  44. data/spec/cli_spec.rb +34 -0
  45. data/spec/post_install_message_spec.rb +6 -0
  46. data/spec/spec_helper.rb +17 -0
  47. data/spec/version_spec.rb +5 -0
  48. metadata +105 -21
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 822b87be11c648dbd2259e0e5dccd1f5c81021cc
4
- data.tar.gz: e5dc07556f85dbe87db082540021bf8488dc3dab
3
+ metadata.gz: 111951a96d22aa5ccce24cddd282f237f20c6c7f
4
+ data.tar.gz: b5ddb1136118fbfa0dc559187c295716dd7a5d6d
5
5
  SHA512:
6
- metadata.gz: 28047a1acbc2a3eeed88b58017fbeac0dc232c0bc368b426896e47205a7fc66bca28eaf29ac3506a064526c9a19732b126c20c61e06d466f1236067a5d46c034
7
- data.tar.gz: b9c5052aadca607d6143364d60ee945bd7cb3e072e0cbe67c61481f49ec0d2a83b6a2b9230801976d2bd84fa925c9bf71d4065acd807f6d27509c41b55ebe682
6
+ metadata.gz: af6fa38ba1eda90668bc862d8e06fef0d57ccf6d3283d2fb3e530780796761417d59b298c7460e9f93aedbe8410bf56f77262699857dd29fa7986b7285266c7a
7
+ data.tar.gz: e2064fa585c0485126b2ecc48624d0d7726a43e203d2ac6c3f1aabe63f4deb13c85f499daf20e7196b024f749804f5b87286ab83023a7e8488f2ef465717e82c
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ *.sh
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
@@ -1,5 +1,5 @@
1
1
  Copyright (c) 2013 Tawheed Abdul-Raheem
2
-
2
+
3
3
  MIT License
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
data/README.md CHANGED
@@ -18,13 +18,13 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- `backone_generator new app_name`
22
- `backone_generator model model_name`
23
- `backone_generator view view_name`
24
- `backone_generator route route_name`
25
- `backone_generator collection collection_name`
26
- `backone_generator utility utility_name`
27
- `backone_generator library library_name`
21
+ `backbone_generator new app_name`
22
+ `backbone_generator model model_name`
23
+ `backbone_generator view view_name`
24
+ `backbone_generator route route_name`
25
+ `backbone_generator collection collection_name`
26
+ `backbone_generator utility utility_name`
27
+ `backbone_generator library library_name`
28
28
 
29
29
  ## Contributing
30
30
 
@@ -33,3 +33,6 @@ Or install it yourself as:
33
33
  3. Commit your changes (`git commit -am 'Add some feature'`)
34
34
  4. Push to the branch (`git push origin my-new-feature`)
35
35
  5. Create new Pull Request
36
+
37
+ ## Credit
38
+ Mhd Tahawi for code refactor
@@ -2,6 +2,7 @@
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'backbone_generator/version'
5
+ require 'backbone_generator/post_install_message'
5
6
 
6
7
  Gem::Specification.new do |spec|
7
8
  spec.name = "backbone_generator"
@@ -9,8 +10,8 @@ Gem::Specification.new do |spec|
9
10
  spec.authors = ["Tawheed Abdul-Raheem"]
10
11
  spec.email = ["tawrahim@gmail.com"]
11
12
  spec.description = %q{Backbone.js generator}
12
- spec.summary = %q{Backbone.js generator}
13
- spec.homepage = ""
13
+ spec.summary = %q{Yet another backbone js generator}
14
+ spec.homepage = "http://tawrahim.github.io/backbone_generator_web/"
14
15
  spec.license = "MIT"
15
16
 
16
17
  spec.files = `git ls-files`.split($/)
@@ -18,20 +19,13 @@ Gem::Specification.new do |spec|
18
19
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
20
  spec.require_paths = ["lib"]
20
21
 
21
- spec.add_development_dependency "bundler", "~> 1.3"
22
+
22
23
  spec.add_development_dependency "rake"
24
+ spec.add_development_dependency "bundler", "~> 1.3"
25
+ spec.add_development_dependency "rspec", "~> 2.6"
23
26
 
24
- spec.post_install_message = <<-EOS
25
-
26
- ==== Release notes for BackboneGenerator gem ====
27
-
28
- This gem is NOT yet ready for prime time. PLEASE DO NOT
29
- USE this gem yet. We are working hard to make dependecy
30
- management and boiler plate code generation in your
31
- backbone.js apps seameless.
32
-
33
- Tawheed and Mhd
27
+ spec.add_dependency "thor"
28
+ spec.add_dependency "colorize", "~>0.6.0"
34
29
 
35
- =======================================
36
- EOS
30
+ spec.post_install_message = BackboneGenerator.post_install_message
37
31
  end
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "backbone_generator"
4
+ require "backbone_generator/cli"
5
+
6
+ BackboneGenerator::CLI.start
@@ -1,6 +1,18 @@
1
+ require "thor"
2
+ require "webrick"
3
+ require "colorize"
1
4
  require "backbone_generator/version"
5
+ require "backbone_generator/auxilliary"
6
+ require "backbone_generator/generators/collections/collections_generator.rb"
7
+ require "backbone_generator/generators/library/library_generator.rb"
8
+ require "backbone_generator/generators/models/models_generator.rb"
9
+ require "backbone_generator/generators/new/new_generator.rb"
10
+ require "backbone_generator/generators/route/route_generator.rb"
11
+ require "backbone_generator/generators/templates/templates_generator.rb"
12
+ require "backbone_generator/generators/tests/tests_generator.rb"
13
+ require "backbone_generator/generators/utilities/utilities_generator.rb"
14
+ require "backbone_generator/generators/views/views_generator.rb"
2
15
 
3
16
  module BackboneGenerator
4
17
  # Your code goes here...
5
- puts "hello world"
6
18
  end
@@ -0,0 +1,44 @@
1
+ require "erb"
2
+
3
+ # Namespace for all the classess
4
+ # @since 0.0.3
5
+ module BackboneGenerator
6
+
7
+ class << self
8
+
9
+ # This app hold the details of the app
10
+ @@option_details = {}
11
+
12
+ # This code is dummed down version of template_method in the bundler
13
+ # gem. Original version can be found
14
+ # @see https://github.com/bundler/bundler/blob/master/lib/bundler/vendor/thor/actions/file_manipulation.rb
15
+ # God Bless all the great and awesome people who brought us open source
16
+ # God Bless all the ruby developers out there!
17
+ def compile_and_copy(source_file, *args)
18
+ config = args.last.is_a?(Hash) ? args.pop : {}
19
+ destination = args.first
20
+ context = instance_eval('binding')
21
+ content = ERB.new(::File.binread(source_file)).result(context)
22
+ open(destination, 'w') { |f| f << content }
23
+ end
24
+
25
+ # Function used to start server
26
+ def start_server(port)
27
+ root = Dir.getwd
28
+ server = WEBrick::HTTPServer.new :Port => port, :DocumentRoot => root
29
+ trap 'INT' do server.shutdown end
30
+ server.start
31
+ end
32
+
33
+ # Getter for the option_details hash
34
+ def option_details
35
+ @@option_details
36
+ end
37
+
38
+ # Setter for the option_details hash
39
+ def option_details=(value)
40
+ @@option_details = value
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,79 @@
1
+ # Namespace for all the classess
2
+ # @since 0.0.3
3
+ module BackboneGenerator
4
+
5
+ # Abstract base class for CLI utilities
6
+ #
7
+ # @author Tawheed Abdul-Raheem
8
+ # @abstract
9
+ # @since 0.0.3
10
+ class CLI < Thor
11
+
12
+ private
13
+ def isvalid?
14
+ if File.exists? ".BACKBONE_GENERATOR_APP"
15
+ return true
16
+ else
17
+ print "error ".red
18
+ puts "This command must be excuted in the root level of your app"
19
+ return false
20
+ end
21
+ end
22
+
23
+ public
24
+ desc "new app_name", "Create a new backbone.js application named app_name"
25
+ def new app_name
26
+ if File.exists? app_name
27
+ print "error ".red
28
+ puts "A folder with the name " + app_name + " already exists"
29
+ else
30
+ BackboneGenerator::NewGenerator.new app_name
31
+ end
32
+ end
33
+
34
+ desc "model model_name", "Create a new backbone.js model named model_name "
35
+ def model model_name
36
+ BackboneGenerator::ModelGenerator.create_model(model_name) unless !isvalid?
37
+ end
38
+
39
+ desc "view view_name", "Create a new backbone.js view named view_name"
40
+ def view view_name
41
+ BackboneGenerator::ViewGenerator.create_view(view_name) unless !isvalid?
42
+ end
43
+
44
+ desc "route route_name", "Create a new backbone.js route named route_name"
45
+ def route route_name
46
+ BackboneGenerator::RouteGenerator.create_route(route_name) unless !isvalid?
47
+ end
48
+
49
+ desc " collection collection_name", "Create a new backbone.js collection named collection_name"
50
+ def collection collection_name
51
+ BackboneGenerator::CollectionGenerator.create_collection(collection_name) unless !isvalid?
52
+ end
53
+
54
+ desc "utility utility_name", "Create a new backbone.js utility named utility_name"
55
+ def utility utility_name
56
+ BackboneGenerator::UtilityGenerator.create_utility(utility_name) unless !isvalid?
57
+ end
58
+
59
+ desc "template template_name", "Create a template associated with a view"
60
+ def template template_name
61
+ BackboneGenerator::TemplateGenerator.create_template(template_name) unless !isvalid?
62
+ end
63
+
64
+ desc "library library_name", "Create a new backbone.js library named library_name"
65
+ def library library_name
66
+ BackboneGenerator::LibraryGenerator.fetch_library(library_name) unless !isvalid?
67
+ end
68
+
69
+ desc "test test_name", "Create a new jasmine test"
70
+ def test test_name
71
+ BackboneGenerator::TestGenerator.create_test(test_name) unless !isvalid?
72
+ end
73
+
74
+ desc "server", "Start a server, it defaults to port 5000 or you can pass a second argumnent for the port"
75
+ def server(port=5000)
76
+ BackboneGenerator.start_server(port) unless !isvalid?
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,35 @@
1
+ # Namespace for all the classess
2
+ # @since 0.0.3
3
+ module BackboneGenerator
4
+
5
+ # Abstract base class for generating
6
+ # collection A.K.A copying template
7
+ # @author Tawheed Abdul-Raheem
8
+ class CollectionGenerator
9
+
10
+ class << self
11
+ def create_collection collection_name
12
+ app_name = BackboneGenerator.option_details[:app_name] || File.basename(Dir.getwd).chomp("/")
13
+ if BackboneGenerator.option_details[:app_name]
14
+ dir_path = File.join(Dir.getwd, app_name)
15
+ else
16
+ dir_path = File.join(Dir.getwd)
17
+ end
18
+ template_path = File.expand_path(File.dirname(__FILE__)) + "/template/Collection.tt"
19
+ target_path = "/js/collections/" + collection_name.capitalize + ".Collection.js"
20
+ collection_hash = {
21
+ :app_name => app_name.slice(0,1).capitalize + app_name.slice(1..-1),
22
+ :collection_name => collection_name.slice(0,1).capitalize + collection_name.slice(1..-1),
23
+ }
24
+ if File.exist? dir_path + target_path
25
+ print "error ".red
26
+ puts "Collection with the name specified already exists"
27
+ else
28
+ BackboneGenerator.compile_and_copy(template_path, dir_path + target_path, collection_hash)
29
+ print "created ".green
30
+ puts collection_hash[:app_name] + target_path
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,29 @@
1
+ /**
2
+ * TODO: add description of class
3
+ * @author:
4
+ * @class: <%= config[:collection_name] %>Collection
5
+ * */
6
+
7
+ /* global define */
8
+ var <%= config[:app_name] %> = <%= config[:app_name] %> || {};
9
+
10
+ (function() {
11
+ 'use strict';
12
+
13
+ define([
14
+ 'jquery',
15
+ 'underscore',
16
+ 'backbone',
17
+ ], function($, _, Backbone) {
18
+
19
+ // Collection is a group of models that have custom methods
20
+ // that you create for them
21
+ <%= config[:app_name] %>.<%= config[:collection_name] %>Collection = Backbone.Collection.extend({
22
+
23
+ //TODO: Place your collection code here
24
+
25
+ });
26
+
27
+ return <%= config[:app_name] %>.<%= config[:collection_name] %>Collection;
28
+ });
29
+ }());
@@ -0,0 +1,17 @@
1
+ # Namespace for all the classess
2
+ # @since 0.0.3
3
+ module BackboneGenerator
4
+
5
+ # Abstract base class for fetching
6
+ # javascript libaries from the internet
7
+ # @author Tawheed Abdul-Raheem
8
+ class ModelGenerator
9
+
10
+ class << self
11
+ def fetch_library library_name
12
+ print "NOTICE ".yellow
13
+ puts "Will be implemented in the next Release"
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,35 @@
1
+ # Namespace for all the classess
2
+ # @since 0.0.3
3
+ module BackboneGenerator
4
+
5
+ # Abstract base class for generating
6
+ # models A.K.A copying template
7
+ # @author Tawheed Abdul-Raheem
8
+ class ModelGenerator
9
+
10
+ class << self
11
+ def create_model model_name
12
+ app_name = BackboneGenerator.option_details[:app_name] || File.basename(Dir.getwd).chomp("/")
13
+ if BackboneGenerator.option_details[:app_name]
14
+ dir_path = File.join(Dir.getwd, app_name)
15
+ else
16
+ dir_path = File.join(Dir.getwd)
17
+ end
18
+ template_path = File.expand_path(File.dirname(__FILE__)) + "/template/Model.tt"
19
+ target_path = "/js/models/" + model_name.capitalize + ".Model.js"
20
+ model_hash = {
21
+ :app_name => app_name.slice(0,1).capitalize + app_name.slice(1..-1),
22
+ :model_name => model_name.slice(0,1).capitalize + model_name.slice(1..-1),
23
+ }
24
+ if File.exist? dir_path + target_path
25
+ print "error ".red
26
+ puts "Model with the name specified already exists"
27
+ else
28
+ BackboneGenerator.compile_and_copy(template_path, dir_path + target_path, model_hash)
29
+ print "created ".green
30
+ puts model_hash[:app_name] + target_path
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,44 @@
1
+ /**
2
+ * TODO: add description of class
3
+ * @author:
4
+ * @class: <%= config[:model_name] %>Model
5
+ * */
6
+
7
+ /* global define */
8
+ var <%= config[:app_name] %> = <%= config[:app_name] %> || {};
9
+
10
+ (function() {
11
+ 'use strict';
12
+
13
+ define([
14
+ 'jquery',
15
+ 'underscore',
16
+ 'backbone',
17
+ ], function($, _, Backbone) {
18
+
19
+ <%= config[:app_name] %>.<%= config[:model_name] %>Model = Backbone.Model.extend({
20
+
21
+ //TODO: Add any default model object here
22
+ defaults: {
23
+ foo: "I am a data memeber"
24
+ },
25
+
26
+ //TODO: Add any initialization code here
27
+ initialize: function() {
28
+ console.log("Initializing main <%= config[:model_name] %> model");
29
+ },
30
+
31
+ //TODO: Getters and Setters for the model object
32
+ getfoo: function() {
33
+ return this.get('foo');
34
+ },
35
+
36
+ setfoo: function(value) {
37
+ this.set('foo', value);
38
+ },
39
+
40
+ });
41
+
42
+ return <%= config[:app_name] %>.<%= config[:model_name] %>Model;
43
+ });
44
+ }());
@@ -0,0 +1,89 @@
1
+ # Namespace for all the classess
2
+ # @since 0.0.3
3
+ module BackboneGenerator
4
+
5
+ # Abstract base class for generating a project
6
+ #
7
+ # @author Tawheed Abdul-Raheem
8
+ # @abstract
9
+ # @since 0.0.3
10
+ class NewGenerator
11
+
12
+ def initialize app_name
13
+ @app_name = app_name.chomp("/")
14
+ @target_path = File.join(Dir.getwd, @app_name)
15
+ @template_path = File.expand_path(File.dirname(__FILE__)) + "/template"
16
+ Dir.mkdir (@target_path)
17
+
18
+ git_user_name = `git config user.name`.chomp
19
+ git_user_email = `git config user.email`.chomp
20
+
21
+ BackboneGenerator.option_details.merge!({
22
+ :app_name => @app_name.slice(0,1).capitalize + @app_name.slice(1..-1),
23
+ :app_path => @target_path,
24
+ :author => git_user_name.empty? ? "TODO: Write your name" : git_user_name,
25
+ :email => git_user_email.empty? ? "TODO: Write your email address" : git_user_email,
26
+ })
27
+ BackboneGenerator.option_details.freeze
28
+ copy_static_files
29
+ copy_compiled_files
30
+ puts "Initializing git repo in " + Dir.getwd + "/" + app_name
31
+ Dir.chdir(@target_path) { `git init`; `git add .` }
32
+ end
33
+
34
+ def copy_static_files
35
+ dot_files = ["/.gitignore", "/.BACKBONE_GENERATOR_APP", "/index.html"]
36
+ dot_files.each do |file|
37
+ FileUtils.cp(@template_path + file, @target_path)
38
+ print "created ".green
39
+ puts BackboneGenerator.option_details[:app_name] + file
40
+ end
41
+
42
+ js_files = ['/js/collections', '/js/models', '/js/views', '/js/templates', '/js/utilities', '/js/libs', '/js/routes']
43
+ js_files.each do |file|
44
+ FileUtils.mkdir_p @target_path + file
45
+ end
46
+
47
+ FileUtils.cp_r(Dir.glob(@template_path + '/js/libs/'), @target_path + '/js/')
48
+
49
+ css_img = ["/css", "/img"]
50
+ css_img.each do |file|
51
+ FileUtils.cp_r(Dir.glob(@template_path + file), @target_path)
52
+ end
53
+
54
+ # comments to display
55
+ print "created ".green
56
+ puts BackboneGenerator.option_details[:app_name] + "/css/main.css"
57
+ print "created ".green
58
+ puts BackboneGenerator.option_details[:app_name] + "/img/backbone.png"
59
+ end
60
+
61
+ def copy_compiled_files
62
+ templates_hash = {
63
+ "/README.tt" => "/README.md",
64
+ "/main.tt" => "/js/app.js",
65
+ "/js/views/Main.View.tt" => "/js/views/Main.View.js"
66
+ }
67
+ templates_hash.each do |key, value|
68
+ BackboneGenerator.compile_and_copy(@template_path + key, @target_path + value, BackboneGenerator.option_details)
69
+ print "created ".green
70
+ puts BackboneGenerator.option_details[:app_name] + value
71
+ end
72
+
73
+ BackboneGenerator::ViewGenerator.create_view("hello")
74
+ BackboneGenerator::ModelGenerator.create_model("hello")
75
+ BackboneGenerator::CollectionGenerator.create_collection("hello")
76
+ BackboneGenerator::RouteGenerator.create_route(BackboneGenerator.option_details[:app_name])
77
+ BackboneGenerator::UtilityGenerator.create_utility(BackboneGenerator.option_details[:app_name])
78
+ # This is some hacky stuff! Will remove in future release, Beacuse
79
+ # the initial template contains a special message from me, there got
80
+ # to be a way to replace the message so that it only appears the first time
81
+ # to resolve this problem, I am simply going to override the contents
82
+ # of the file with a standard default template
83
+ open(File.expand_path("..",File.dirname(__FILE__)) + "/templates/template/Template.tt", 'w') do |f|
84
+ f.puts '<p> I am the template for <%= config[:template_name] %> </p>'
85
+ end
86
+
87
+ end
88
+ end
89
+ end