brancusi-rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. data/Rakefile +40 -0
  2. data/app/helpers/template_helper.rb +24 -0
  3. data/config/routes.rb +2 -0
  4. data/lib/brancusi-rails.rb +4 -0
  5. data/lib/brancusi-rails/engine.rb +4 -0
  6. data/lib/brancusi-rails/version.rb +3 -0
  7. data/lib/generators/brancusi/controller/USAGE +8 -0
  8. data/lib/generators/brancusi/controller/controller_generator.rb +14 -0
  9. data/lib/generators/brancusi/controller/templates/controller.rb +6 -0
  10. data/lib/generators/brancusi/init/USAGE +8 -0
  11. data/lib/generators/brancusi/init/init_generator.rb +46 -0
  12. data/lib/generators/brancusi/init/templates/app/assets/javascripts/app/config/application.js.coffee +3 -0
  13. data/lib/generators/brancusi/init/templates/app/assets/javascripts/app/config/bootstrapper.js.coffee +7 -0
  14. data/lib/generators/brancusi/init/templates/app/assets/javascripts/app/config/index.js.coffee +2 -0
  15. data/lib/generators/brancusi/init/templates/app/assets/javascripts/app/config/routes.js.coffee +10 -0
  16. data/lib/generators/brancusi/init/templates/app/assets/javascripts/app/index.js.coffee +2 -0
  17. data/lib/generators/brancusi/init/templates/app/controllers/main_controller.rb +4 -0
  18. data/lib/generators/brancusi/init/templates/app/views/main/index.html.erb +8 -0
  19. data/lib/generators/brancusi/init/templates/app/views/templates/_header.html.erb +1 -0
  20. data/lib/generators/brancusi/init/templates/app/views/templates/_master.html.erb +9 -0
  21. data/lib/generators/brancusi/module/USAGE +8 -0
  22. data/lib/generators/brancusi/module/module_generator.rb +11 -0
  23. data/lib/generators/brancusi/module/templates/module.rb +5 -0
  24. data/lib/generators/brancusi/view/USAGE +8 -0
  25. data/lib/generators/brancusi/view/templates/view.rb +1 -0
  26. data/lib/generators/brancusi/view/view_generator.rb +9 -0
  27. data/lib/tasks/brancusi-rails_tasks.rake +4 -0
  28. data/test/brancusi-rails_test.rb +7 -0
  29. data/test/integration/navigation_test.rb +10 -0
  30. data/test/test_helper.rb +15 -0
  31. metadata +148 -0
@@ -0,0 +1,40 @@
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 = 'BrancusiRails'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
24
+ load 'rails/tasks/engine.rake'
25
+
26
+
27
+
28
+ Bundler::GemHelper.install_tasks
29
+
30
+ require 'rake/testtask'
31
+
32
+ Rake::TestTask.new(:test) do |t|
33
+ t.libs << 'lib'
34
+ t.libs << 'test'
35
+ t.pattern = 'test/**/*_test.rb'
36
+ t.verbose = false
37
+ end
38
+
39
+
40
+ task :default => :test
@@ -0,0 +1,24 @@
1
+ module TemplateHelper
2
+ def render_templates
3
+ templates = load_templates.collect do |t|
4
+ "<script type='text/template' id='#{t[:id]}'>#{t[:content]}</script>"
5
+ end
6
+ raw(templates.join)
7
+ end
8
+
9
+ private
10
+ def load_templates
11
+ templates = []
12
+ Dir.glob("app/views/templates/**/*.*").each do |file_name|
13
+ puts "*** scanning: #{file_name}"
14
+ matches = /app\/views\/templates\/(.*?)_([\w\.]+)\.html\.(haml|erb)/.match file_name
15
+ if matches
16
+ puts "*** matched: #{file_name}"
17
+ tmpl_name = "#{matches[1]}#{matches[2]}"
18
+ tmpl_content = render :partial => "templates/#{tmpl_name}"
19
+ templates << { :id => "template:#{tmpl_name}", :content => tmpl_content }
20
+ end
21
+ end
22
+ templates
23
+ end
24
+ end
@@ -0,0 +1,2 @@
1
+ Rails.application.routes.draw do
2
+ end
@@ -0,0 +1,4 @@
1
+ require "brancusi-rails/engine"
2
+
3
+ module BrancusiRails
4
+ end
@@ -0,0 +1,4 @@
1
+ module BrancusiRails
2
+ class Engine < ::Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module BrancusiRails
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ rails generate controller Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,14 @@
1
+ module Brancusi
2
+ class ControllerGenerator < Rails::Generators::NamedBase
3
+ source_root File.expand_path('../templates', __FILE__)
4
+
5
+ argument :actions, :type => :array, :default => [], :banner => "action action"
6
+
7
+ def create_controller
8
+ template 'controller.rb', File.join("app/assets/javascripts/app/controllers", "#{file_name}_controller.js.coffee")
9
+ actions.each do |action|
10
+ generate('brancusi:view', "#{file_name}/#{action}")
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,6 @@
1
+ class Application.Controllers.<%= class_name %>Controller extends brancusi.ApplicationController
2
+ <% actions.each do |action| -%>
3
+
4
+ <%= action %>: ->
5
+ @render()
6
+ <% end -%>
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ rails generate init Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,46 @@
1
+ module Brancusi
2
+ class InitGenerator < Rails::Generators::Base
3
+ source_root File.expand_path('../templates', __FILE__)
4
+
5
+ def inject_brancusi
6
+ application_file = File.join("app/assets/javascripts", "application.js")
7
+ # file_type = :javascript
8
+ pattern = /\/\/=(?!.*\/\/=).*?$/m
9
+
10
+ # raise Thor::Error, "Couldn't find either application.js or application.js.coffee files for use with Brancusi!" unless exists?(application_file)
11
+
12
+ inject_into_file application_file, :before=>pattern do
13
+ "//= require brancusi \n//= require app \n"
14
+ end
15
+ end
16
+
17
+ def inject_javascripts
18
+ layout_file = File.join("app/views/layouts/application.html.erb")
19
+ pattern = /<%= javascript_include_tag "application" %>/
20
+
21
+ inject_into_file layout_file, :before => pattern do
22
+ ['<%= javascript_include_tag "//cdnjs.cloudflare.com/ajax/libs/jquery/1.8.3/jquery.min.js" %>',
23
+ '<%= javascript_include_tag "//cdnjs.cloudflare.com/ajax/libs/davis.js/0.9.5/davis.min.js" %>',
24
+ '<%= javascript_include_tag "//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.3/underscore-min.js" %>',
25
+ '<%= javascript_include_tag "//cdnjs.cloudflare.com/ajax/libs/underscore.string/2.3.0/underscore.string.min.js" %>',
26
+ '<%= javascript_include_tag "//cdnjs.cloudflare.com/ajax/libs/knockout/2.2.1/knockout-min.js" %>'].
27
+ map { |s| "#{s}\n " }.
28
+ join
29
+ end
30
+ end
31
+
32
+ def copy_app
33
+ directory "app/assets/javascripts/app"
34
+ copy_file "app/controllers/main_controller.rb"
35
+ copy_file "app/views/main/index.html.erb"
36
+ directory "app/views/templates"
37
+ end
38
+
39
+ def define_routes
40
+ # TODO: do we need the root :to?
41
+ route("root :to => 'main#index'")
42
+ route("match '/*id' => 'main#index', id: /(?!api|assets).*/")
43
+ end
44
+
45
+ end
46
+ end
@@ -0,0 +1,3 @@
1
+ class window.Application extends brancusi.Application
2
+ @dependency router: 'Router'
3
+ @dependency renderer: 'Renderer'
@@ -0,0 +1,7 @@
1
+ class Application.Bootstrapper extends brancusi.Bootstrapper
2
+ configure_container: (app) ->
3
+ container = super(app)
4
+ container.register_class 'Router', brancusi.routes.DavisRouter, singleton: true
5
+ container.register_class 'Renderer', brancusi.renderer.KnockoutRenderer, singleton: true
6
+ container
7
+
@@ -0,0 +1,2 @@
1
+ #= require ./application
2
+ #= require_tree .
@@ -0,0 +1,10 @@
1
+ Application.routes.draw ->
2
+ # match a URL
3
+ # @match '/', 'home#index'
4
+
5
+ # match with params
6
+ # @match '/users/:id', 'users#view'
7
+
8
+ # Execute the router on the first page load. Comment this out if you instead generate content on
9
+ # the server during the first request.
10
+ Application.config.route_on_load = true
@@ -0,0 +1,2 @@
1
+ #= require ./config
2
+ #= require_tree .
@@ -0,0 +1,4 @@
1
+ class MainController < ApplicationController
2
+ def index
3
+ end
4
+ end
@@ -0,0 +1,8 @@
1
+ <div data-region="master">
2
+ </div>
3
+
4
+ <%= render_templates %>
5
+
6
+ <script type="text/javascript">
7
+ Application.run();
8
+ </script>
@@ -0,0 +1 @@
1
+ <p>Header template defined in app/views/templates/_header.html.erb</p>
@@ -0,0 +1,9 @@
1
+ <div class="header" data-region="header">
2
+ </div>
3
+
4
+ <div class="content" data-region="content">
5
+ </div>
6
+
7
+ <div class="footer">
8
+ <p>Master template defined in app/views/templates/_master.html.erb</p>
9
+ </div>
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ rails generate module Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,11 @@
1
+ module Brancusi
2
+ class ModuleGenerator < Rails::Generators::NamedBase
3
+ source_root File.expand_path('../templates', __FILE__)
4
+
5
+ argument :actions, :type => :array, :default => [], :banner => "action action"
6
+
7
+ def create_module
8
+ template 'module.rb', File.join("app/assets/javascripts/app/modules", "#{file_name}_module.js.coffee")
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ class Application.Modules.<%= class_name %>Module extends brancusi.ApplicationModule
2
+ <% actions.each do |action| -%>
3
+
4
+ <%= action %>: ->
5
+ <% end -%>
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ rails generate view Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1 @@
1
+ <p>Find me in app/assets/javascripts/app/views/_<%= file_name %>.html.erb</p>
@@ -0,0 +1,9 @@
1
+ module Brancusi
2
+ class ViewGenerator < Rails::Generators::NamedBase
3
+ source_root File.expand_path('../templates', __FILE__)
4
+
5
+ def create_view
6
+ template 'view.rb', File.join("app/views/templates", class_path, "_#{file_name}.html.erb")
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :brancusi-rails do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class BrancusiRailsTest < ActiveSupport::TestCase
4
+ test "truth" do
5
+ assert_kind_of Module, BrancusiRails
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ require 'test_helper'
2
+
3
+ class NavigationTest < ActionDispatch::IntegrationTest
4
+ fixtures :all
5
+
6
+ # test "the truth" do
7
+ # assert true
8
+ # end
9
+ end
10
+
@@ -0,0 +1,15 @@
1
+ # Configure Rails Environment
2
+ ENV["RAILS_ENV"] = "test"
3
+
4
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
5
+ require "rails/test_help"
6
+
7
+ Rails.backtrace_cleaner.remove_silencers!
8
+
9
+ # Load support files
10
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
11
+
12
+ # Load fixtures from the engine
13
+ if ActiveSupport::TestCase.method_defined?(:fixture_path=)
14
+ ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
15
+ end
metadata ADDED
@@ -0,0 +1,148 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: brancusi-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - John Brunton
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 3.2.11
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 3.2.11
30
+ - !ruby/object:Gem::Dependency
31
+ name: coffee-rails
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: brancusi
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: sqlite3
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: Rails support for Brancusi.js
79
+ email:
80
+ - john_brunton@hotmail.co.uk
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - app/helpers/template_helper.rb
86
+ - config/routes.rb
87
+ - lib/brancusi-rails/engine.rb
88
+ - lib/brancusi-rails/version.rb
89
+ - lib/brancusi-rails.rb
90
+ - lib/generators/brancusi/controller/controller_generator.rb
91
+ - lib/generators/brancusi/controller/templates/controller.rb
92
+ - lib/generators/brancusi/controller/USAGE
93
+ - lib/generators/brancusi/init/init_generator.rb
94
+ - lib/generators/brancusi/init/templates/app/assets/javascripts/app/config/application.js.coffee
95
+ - lib/generators/brancusi/init/templates/app/assets/javascripts/app/config/bootstrapper.js.coffee
96
+ - lib/generators/brancusi/init/templates/app/assets/javascripts/app/config/index.js.coffee
97
+ - lib/generators/brancusi/init/templates/app/assets/javascripts/app/config/routes.js.coffee
98
+ - lib/generators/brancusi/init/templates/app/assets/javascripts/app/index.js.coffee
99
+ - lib/generators/brancusi/init/templates/app/controllers/main_controller.rb
100
+ - lib/generators/brancusi/init/templates/app/views/main/index.html.erb
101
+ - lib/generators/brancusi/init/templates/app/views/templates/_header.html.erb
102
+ - lib/generators/brancusi/init/templates/app/views/templates/_master.html.erb
103
+ - lib/generators/brancusi/init/USAGE
104
+ - lib/generators/brancusi/module/module_generator.rb
105
+ - lib/generators/brancusi/module/templates/module.rb
106
+ - lib/generators/brancusi/module/USAGE
107
+ - lib/generators/brancusi/view/templates/view.rb
108
+ - lib/generators/brancusi/view/USAGE
109
+ - lib/generators/brancusi/view/view_generator.rb
110
+ - lib/tasks/brancusi-rails_tasks.rake
111
+ - Rakefile
112
+ - test/brancusi-rails_test.rb
113
+ - test/integration/navigation_test.rb
114
+ - test/test_helper.rb
115
+ homepage: https://github.com/jbrunton/brancusi-rails
116
+ licenses: []
117
+ post_install_message:
118
+ rdoc_options: []
119
+ require_paths:
120
+ - lib
121
+ required_ruby_version: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ! '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ segments:
128
+ - 0
129
+ hash: 2770723036317176464
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ none: false
132
+ requirements:
133
+ - - ! '>='
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ segments:
137
+ - 0
138
+ hash: 2770723036317176464
139
+ requirements: []
140
+ rubyforge_project:
141
+ rubygems_version: 1.8.24
142
+ signing_key:
143
+ specification_version: 3
144
+ summary: Rails support for Brancusi.js
145
+ test_files:
146
+ - test/brancusi-rails_test.rb
147
+ - test/integration/navigation_test.rb
148
+ - test/test_helper.rb