hanber-rails 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/.DS_Store +0 -0
- data/.gitignore +17 -0
- data/Appraisals +10 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +44 -0
- data/README.md +29 -0
- data/Rakefile +14 -0
- data/hanber-rails.gemspec +29 -0
- data/lib/.DS_Store +0 -0
- data/lib/generators/.DS_Store +0 -0
- data/lib/generators/hanber/.DS_Store +0 -0
- data/lib/generators/hanber/bootstrap_generator.rb +56 -0
- data/lib/generators/hanber/controller_generator.rb +24 -0
- data/lib/generators/hanber/generator_helpers.rb +19 -0
- data/lib/generators/hanber/install_generator.rb +94 -0
- data/lib/generators/hanber/model_generator.rb +44 -0
- data/lib/generators/hanber/resource_override.rb +32 -0
- data/lib/generators/hanber/route_handler_generator.rb +15 -0
- data/lib/generators/hanber/scaffold_generator.rb +46 -0
- data/lib/generators/hanber/view_generator.rb +20 -0
- data/lib/generators/templates/app.js +11 -0
- data/lib/generators/templates/application.handlebars +3 -0
- data/lib/generators/templates/array_controller.js +3 -0
- data/lib/generators/templates/controller.js +3 -0
- data/lib/generators/templates/model.js +5 -0
- data/lib/generators/templates/object_controller.js +3 -0
- data/lib/generators/templates/route_handler.js +11 -0
- data/lib/generators/templates/router.js +4 -0
- data/lib/generators/templates/scaffolded_route.js +11 -0
- data/lib/generators/templates/store.js +5 -0
- data/lib/generators/templates/view.handlebars +5 -0
- data/lib/generators/templates/view.js +3 -0
- data/lib/hanber/.DS_Store +0 -0
- data/lib/hanber/handlebars/template.rb +96 -0
- data/lib/hanber/handlebars/version.rb +5 -0
- data/lib/hanber/rails/engine.rb +21 -0
- data/lib/hanber/rails/version.rb +5 -0
- data/lib/hanber/version.rb +3 -0
- data/lib/hanber-rails.rb +1 -0
- data/lib/hanber_rails.rb +62 -0
- metadata +197 -0
data/.DS_Store
ADDED
Binary file
|
data/.gitignore
ADDED
data/Appraisals
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
appraise "rails3" do
|
2
|
+
gem 'rails', '~> 3.1'
|
3
|
+
end
|
4
|
+
|
5
|
+
unless RUBY_VERSION == "1.8.7"
|
6
|
+
appraise "rails4" do
|
7
|
+
gem 'rails', :git => 'https://github.com/rails/rails.git'
|
8
|
+
gem 'activerecord-deprecated_finders', :git => 'https://github.com/rails/activerecord-deprecated_finders.git'
|
9
|
+
end
|
10
|
+
end
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
Copyright (c) 2013 logical42
|
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.
|
23
|
+
|
24
|
+
---
|
25
|
+
|
26
|
+
Copyright (c) 2012 Keith Pitt, Rob Monie, Joao Carlos, Paul Chavard and ember-rails contributors
|
27
|
+
|
28
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
29
|
+
this software and associated documentation files (the "Software"), to deal in
|
30
|
+
the Software without restriction, including without limitation the rights to
|
31
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
32
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
33
|
+
so, subject to the following conditions:
|
34
|
+
|
35
|
+
The above copyright notice and this permission notice shall be included in all
|
36
|
+
copies or substantial portions of the Software.
|
37
|
+
|
38
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
39
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
40
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
41
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
42
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
43
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
44
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Hanber::Rails
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'hanber-rails'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install hanber-rails
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require "bundler"
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
require 'appraisal'
|
4
|
+
|
5
|
+
require 'rake/testtask'
|
6
|
+
|
7
|
+
Rake::TestTask.new(:test) do |t|
|
8
|
+
t.libs << 'lib'
|
9
|
+
t.libs << 'test'
|
10
|
+
t.pattern = 'test/**/*_test.rb'
|
11
|
+
t.verbose = false
|
12
|
+
end
|
13
|
+
|
14
|
+
task :default => :test
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'hanber/rails/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "hanber-rails"
|
8
|
+
gem.version = Hanber::Rails::VERSION
|
9
|
+
gem.authors = ["logical42"]
|
10
|
+
gem.email = ["han@thirstlabs.com"]
|
11
|
+
gem.description = %q{ hacked version of ember-rails }
|
12
|
+
gem.summary = %q{ customized version of ember-rails for me, han }
|
13
|
+
gem.homepage = ""
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_dependency "execjs", [">= 1.2"]
|
21
|
+
gem.add_dependency "railties", [">= 3.1"]
|
22
|
+
gem.add_dependency "active_model_serializers"
|
23
|
+
gem.add_dependency "barber"
|
24
|
+
|
25
|
+
gem.add_development_dependency "bundler", [">= 1.2.2"]
|
26
|
+
gem.add_development_dependency "appraisal"
|
27
|
+
gem.add_development_dependency "tzinfo"
|
28
|
+
|
29
|
+
end
|
data/lib/.DS_Store
ADDED
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'generators/hanber/generator_helpers'
|
2
|
+
|
3
|
+
module Hanber
|
4
|
+
module Generators
|
5
|
+
class BootstrapGenerator < ::Rails::Generators::Base
|
6
|
+
include Hanber::Generators::GeneratorHelpers
|
7
|
+
|
8
|
+
source_root File.expand_path("../../templates", __FILE__)
|
9
|
+
|
10
|
+
desc "Creates a default Ember.js folder layout in app/assets/javascripts/ember"
|
11
|
+
|
12
|
+
class_option :skip_git, :type => :boolean, :aliases => "-g", :default => false, :desc => "Skip Git keeps"
|
13
|
+
|
14
|
+
def inject_ember
|
15
|
+
application_file = "app/assets/javascripts/application.js"
|
16
|
+
|
17
|
+
inject_into_file(application_file, :before => "//= require_tree") do
|
18
|
+
dependencies = [
|
19
|
+
# this should eventually become handlebars-runtime when we remove
|
20
|
+
# the runtime dependency on compilation
|
21
|
+
"//= require handlebars",
|
22
|
+
"//= require ember",
|
23
|
+
"//= require ember-data",
|
24
|
+
"//= require_self",
|
25
|
+
"//= require #{application_name.underscore}",
|
26
|
+
"#{application_name.camelize} = Ember.Application.create();"
|
27
|
+
]
|
28
|
+
dependencies.join("\n").concat("\n")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def create_dir_layout
|
33
|
+
%W{models controllers views route_handlers helpers templates}.each do |dir|
|
34
|
+
empty_directory "#{ember_path}/#{dir}"
|
35
|
+
create_file "#{ember_path}/#{dir}/.gitkeep" unless options[:skip_git]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def create_app_file
|
40
|
+
template "app.js", "#{ember_path}/#{application_name.underscore}.js"
|
41
|
+
end
|
42
|
+
|
43
|
+
def create_router_file
|
44
|
+
template "router.js", "#{ember_path}/router.js"
|
45
|
+
end
|
46
|
+
|
47
|
+
def create_store_file
|
48
|
+
template "store.js", "#{ember_path}/store.js"
|
49
|
+
end
|
50
|
+
|
51
|
+
def create_app_stubs
|
52
|
+
generate "ember:view", "application"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'hanber/version'
|
2
|
+
|
3
|
+
module Hanber
|
4
|
+
module Generators
|
5
|
+
class ControllerGenerator < ::Rails::Generators::NamedBase
|
6
|
+
source_root File.expand_path("../../templates", __FILE__)
|
7
|
+
|
8
|
+
desc "Creates a new Ember.js controller"
|
9
|
+
class_option :array, :type => :boolean, :default => false, :desc => "Create an Ember.ArrayController to represent multiple objects"
|
10
|
+
class_option :object, :type => :boolean, :default => false, :desc => "Create an Ember.ObjectController to represent a single object"
|
11
|
+
|
12
|
+
def create_controller_files
|
13
|
+
file_path = File.join('app/assets/javascripts/controllers', class_path, "#{file_name}_controller.js")
|
14
|
+
if options.array?
|
15
|
+
template 'array_controller.js', file_path
|
16
|
+
elsif options.object?
|
17
|
+
template 'object_controller.js', file_path
|
18
|
+
else
|
19
|
+
template 'controller.js', file_path
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Hanber
|
2
|
+
module Generators
|
3
|
+
module GeneratorHelpers
|
4
|
+
|
5
|
+
def ember_path
|
6
|
+
"app/assets/javascripts"
|
7
|
+
end
|
8
|
+
|
9
|
+
def application_name
|
10
|
+
if defined?(::Rails) && ::Rails.application
|
11
|
+
::Rails.application.class.name.split('::').first
|
12
|
+
else
|
13
|
+
"app"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'hanber/version'
|
2
|
+
|
3
|
+
module Hanber
|
4
|
+
module Generators
|
5
|
+
class InstallGenerator < ::Rails::Generators::Base
|
6
|
+
desc "Install Ember.js into your vendor folder"
|
7
|
+
class_option :head, :type => :boolean, :default => false, :desc => "Download latest Ember.js from GitHub and copy it into your project"
|
8
|
+
|
9
|
+
def copy_ember
|
10
|
+
if options.head?
|
11
|
+
|
12
|
+
git_root = File.expand_path "~/.ember"
|
13
|
+
gem_file = File.join git_root, "Gemfile"
|
14
|
+
|
15
|
+
# If it doesn't exist yet
|
16
|
+
unless File.exist?(git_root)
|
17
|
+
command = %{git clone git://github.com/emberjs/ember.js.git "#{git_root}"}
|
18
|
+
say_status("downloading", command, :green)
|
19
|
+
|
20
|
+
cmd command
|
21
|
+
else
|
22
|
+
Dir.chdir git_root do
|
23
|
+
command = "git fetch origin && git reset origin/master --hard"
|
24
|
+
say_status("updating", command, :green)
|
25
|
+
|
26
|
+
cmd command
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
Dir.chdir git_root do
|
31
|
+
say_status("building", "bundle && bundle exec rake dist", :green)
|
32
|
+
Bundler.with_clean_env do
|
33
|
+
cmd "bundle --gemfile #{gem_file}"
|
34
|
+
cmd %{BUNDLE_GEMFILE="#{gem_file}" bundle exec rake dist}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
source_paths << File.join(git_root, "dist")
|
39
|
+
|
40
|
+
copy_file "ember.js", "vendor/assets/ember/development/ember.js"
|
41
|
+
copy_file "ember.min.js", "vendor/assets/ember/production/ember.js"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def copy_ember_data
|
46
|
+
if options.head?
|
47
|
+
|
48
|
+
git_root = File.expand_path "~/.ember-data"
|
49
|
+
gem_file = File.join git_root, "Gemfile"
|
50
|
+
|
51
|
+
# If it doesn't exist yet
|
52
|
+
unless File.exist?(git_root)
|
53
|
+
command = %{git clone git://github.com/emberjs/data.git "#{git_root}"}
|
54
|
+
say_status("downloading", command, :green)
|
55
|
+
|
56
|
+
cmd command
|
57
|
+
else
|
58
|
+
Dir.chdir git_root do
|
59
|
+
command = "git fetch origin && git reset origin/master --hard"
|
60
|
+
say_status("updating", command, :green)
|
61
|
+
|
62
|
+
cmd command
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
Dir.chdir git_root do
|
67
|
+
say_status("building", "bundle && bundle exec rake", :green)
|
68
|
+
Bundler.with_clean_env do
|
69
|
+
cmd "bundle --gemfile #{gem_file}"
|
70
|
+
cmd %{BUNDLE_GEMFILE="#{gem_file}" bundle exec rake}
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
source_paths << File.join(git_root, "dist")
|
75
|
+
|
76
|
+
copy_file "ember-data.js", "vendor/assets/ember/development/ember-data.js"
|
77
|
+
copy_file "ember-data.min.js", "vendor/assets/ember/production/ember-data.js"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
private
|
82
|
+
|
83
|
+
def cmd(command)
|
84
|
+
out = `#{command}`
|
85
|
+
|
86
|
+
if $?.exitstatus != 0
|
87
|
+
raise "Command error: command `#{command}` in directory #{Dir.pwd} has failed."
|
88
|
+
end
|
89
|
+
out
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'hanber/version'
|
2
|
+
|
3
|
+
module Hanber
|
4
|
+
module Generators
|
5
|
+
class ModelGenerator < ::Rails::Generators::NamedBase
|
6
|
+
source_root File.expand_path("../../templates", __FILE__)
|
7
|
+
argument :attributes, :type => :array, :default => [], :banner => "field[:type] field[:type] ..."
|
8
|
+
|
9
|
+
desc "Creates a new Ember.js model"
|
10
|
+
|
11
|
+
def create_model_files
|
12
|
+
template 'model.js', File.join('app/assets/javascripts/models', class_path, "#{file_name}.js")
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
EMBER_TYPE_LOOKUP = {
|
17
|
+
nil => 'string',
|
18
|
+
|
19
|
+
binary: 'string',
|
20
|
+
string: 'string',
|
21
|
+
text: 'string',
|
22
|
+
boolean: 'boolean',
|
23
|
+
date: 'date',
|
24
|
+
datetime: 'date',
|
25
|
+
time: 'date',
|
26
|
+
timestamp: 'date',
|
27
|
+
decimal: 'number',
|
28
|
+
float: 'number',
|
29
|
+
integer: 'number',
|
30
|
+
primary_key: 'number'
|
31
|
+
}
|
32
|
+
|
33
|
+
def parse_attributes!
|
34
|
+
self.attributes = (attributes || []).map do |attr|
|
35
|
+
name, type = attr.split(':')
|
36
|
+
key = type.try(:to_sym)
|
37
|
+
ember_type = EMBER_TYPE_LOOKUP[key] || type
|
38
|
+
|
39
|
+
{ name: name, type: ember_type }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require "rails/generators"
|
2
|
+
require "rails/generators/rails/resource/resource_generator"
|
3
|
+
require "generators/hanber/controller_generator"
|
4
|
+
require "generators/hanber/view_generator"
|
5
|
+
|
6
|
+
module Rails
|
7
|
+
module Generators
|
8
|
+
ResourceGenerator.class_eval do
|
9
|
+
def add_ember
|
10
|
+
say_status :invoke, "ember:model", :white
|
11
|
+
with_padding do
|
12
|
+
invoke "ember:model"
|
13
|
+
end
|
14
|
+
|
15
|
+
say_status :invoke, "ember controller and view (singular)", :white
|
16
|
+
with_padding do
|
17
|
+
invoke "ember:view", [singular_name], :object => true
|
18
|
+
end
|
19
|
+
|
20
|
+
@_invocations[Ember::Generators::ControllerGenerator].delete "create_controller_files"
|
21
|
+
@_invocations[Ember::Generators::ViewGenerator].delete "create_view_files"
|
22
|
+
|
23
|
+
say_status :invoke, "ember controller and view (plural)", :white
|
24
|
+
with_padding do
|
25
|
+
invoke "ember:view", [plural_name], :array => true
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'hanber/version'
|
2
|
+
|
3
|
+
module Hanber
|
4
|
+
module Generators
|
5
|
+
class RouteHandlerGenerator < ::Rails::Generators::NamedBase
|
6
|
+
source_root File.expand_path("../../templates", __FILE__)
|
7
|
+
|
8
|
+
desc "Creates a new route handler"
|
9
|
+
|
10
|
+
def create_view_files
|
11
|
+
template 'route_handler.js', File.join('app/assets/javascripts/route_handlers', class_path, "#{file_name}_route.js")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'hanber/version'
|
2
|
+
require 'generators/hanber/generator_helpers'
|
3
|
+
require 'generators/hanber/model_generator'
|
4
|
+
require 'generators/hanber/route_handler_generator'
|
5
|
+
module Hanber
|
6
|
+
module Generators
|
7
|
+
class ScaffoldGenerator < ::Rails::Generators::NamedBase
|
8
|
+
include Hanber::Generators::GeneratorHelpers
|
9
|
+
|
10
|
+
source_root File.expand_path("../../templates", __FILE__)
|
11
|
+
|
12
|
+
argument :attributes, :type => :array, :default => [], :banner => "field[:type] field[:type] ..."
|
13
|
+
class_option :skip_model, :type => :boolean, :default => false, :desc => "Generate with no model file"
|
14
|
+
desc "Scaffold a restful resource for ember similarly to the rails scaffold generator."
|
15
|
+
|
16
|
+
def create_model
|
17
|
+
unless options.skip_model?
|
18
|
+
generate("hanber:model", "#{file_name} #{puts attributes}")
|
19
|
+
end
|
20
|
+
#template 'model.js', File.join('app/assets/javascripts/models', class_path, "#{file_name}.js")
|
21
|
+
end
|
22
|
+
def create_resourceful_route
|
23
|
+
|
24
|
+
insert_into_file "app/assets/javascripts/router.js", after: ".map(function(match) {\n" do
|
25
|
+
%Q(
|
26
|
+
match("/#{file_name.pluralize}").to("#{file_name.pluralize}", function(match) {
|
27
|
+
match("/").to("#{file_name.pluralize}Index");
|
28
|
+
match("/new").to("#{file_name}New");
|
29
|
+
match("/:#{file_name.underscore}_id").to("#{file_name}", function(match) {
|
30
|
+
match('/').to("#{file_name}Show")
|
31
|
+
match("/content").to("#{file_name}Edit");
|
32
|
+
});
|
33
|
+
});
|
34
|
+
)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
def create_route_handlers
|
38
|
+
resource_hash = {show: "#{file_name}Show", index: "#{file_name.pluralize}Index", new: "#{file_name}New", edit: "#{file_name}Edit"}
|
39
|
+
resource_hash.each do |restful_action, restful_name|
|
40
|
+
@rest_action = restful_name
|
41
|
+
template('scaffolded_route.js', File.join("app/assets/javascripts/route_handlers/#{file_name}_routes", class_path, "#{restful_action.to_s}.js"))
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'hanber/version'
|
2
|
+
|
3
|
+
module Hanber
|
4
|
+
module Generators
|
5
|
+
class ViewGenerator < ::Rails::Generators::NamedBase
|
6
|
+
source_root File.expand_path("../../templates", __FILE__)
|
7
|
+
|
8
|
+
desc "Creates a new Ember.js view and associated Handlebars template"
|
9
|
+
class_option :array, :type => :boolean, :default => false, :desc => "Create an Ember.ArrayController to represent multiple objects"
|
10
|
+
class_option :object, :type => :boolean, :default => false, :desc => "Create an Ember.ObjectController to represent a single object"
|
11
|
+
|
12
|
+
def create_view_files
|
13
|
+
template 'view.js', File.join('app/assets/javascripts/views', class_path, "#{file_name}_view.js")
|
14
|
+
template 'view.handlebars', File.join('app/assets/javascripts/templates', class_path, "#{file_name}.hjs")
|
15
|
+
invoke('ember:controller', [ file_name ], options)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
//= require ./store
|
2
|
+
//= require_tree ./models
|
3
|
+
//= require_tree ./controllers
|
4
|
+
//= require_tree ./views
|
5
|
+
//= require_tree ./helpers
|
6
|
+
//= require_tree ./templates
|
7
|
+
//= require router
|
8
|
+
//= require_tree ./route_handlers
|
9
|
+
//= require_self
|
10
|
+
|
11
|
+
<%= application_name.camelize %>.initialize();
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<%= application_name.camelize %>.<%= class_name %>Route = Ember.Route.extend({
|
2
|
+
renderTemplates: function() {
|
3
|
+
this.render('<%= class_name.underscore %>');
|
4
|
+
},
|
5
|
+
setupControllers: function(controller) {
|
6
|
+
|
7
|
+
},
|
8
|
+
enter: function() {
|
9
|
+
console.log("entering <%= class_name.underscore %> route")
|
10
|
+
}
|
11
|
+
});
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<%= application_name.camelize %>.<%= @rest_action.camelize %>Route = Ember.Route.extend({
|
2
|
+
renderTemplates: function() {
|
3
|
+
this.render('<%= @rest_action.underscore %>');
|
4
|
+
},
|
5
|
+
setupControllers: function(controller) {
|
6
|
+
|
7
|
+
},
|
8
|
+
enter: function() {
|
9
|
+
console.log("entering <%= @rest_action.underscore %> route")
|
10
|
+
}
|
11
|
+
});
|
Binary file
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'sprockets'
|
2
|
+
require 'sprockets/engines'
|
3
|
+
require 'barber'
|
4
|
+
|
5
|
+
module Hanber
|
6
|
+
module Handlebars
|
7
|
+
class Template < Tilt::Template
|
8
|
+
def self.default_mime_type
|
9
|
+
'application/javascript'
|
10
|
+
end
|
11
|
+
|
12
|
+
def prepare; end
|
13
|
+
|
14
|
+
def evaluate(scope, locals, &block)
|
15
|
+
target = template_target(scope)
|
16
|
+
raw = handlebars?(scope)
|
17
|
+
|
18
|
+
if raw
|
19
|
+
template = data
|
20
|
+
else
|
21
|
+
template = mustache_to_handlebars(scope, data)
|
22
|
+
end
|
23
|
+
|
24
|
+
if configuration.precompile
|
25
|
+
if raw
|
26
|
+
template = precompile_handlebars(template)
|
27
|
+
else
|
28
|
+
template = precompile_ember_handlebars(template)
|
29
|
+
end
|
30
|
+
else
|
31
|
+
if raw
|
32
|
+
template = compile_handlebars(data)
|
33
|
+
else
|
34
|
+
template = compile_ember_handlebars(template)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
"#{target} = #{template}\n"
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def handlebars?(scope)
|
44
|
+
scope.pathname.to_s =~ /\.raw\.(handlebars|hjs|hbs)/
|
45
|
+
end
|
46
|
+
|
47
|
+
def template_target(scope)
|
48
|
+
"Hanber.TEMPLATES[#{template_path(scope.logical_path).inspect}]"
|
49
|
+
end
|
50
|
+
|
51
|
+
def compile_handlebars(string)
|
52
|
+
"Handlebars.compile(#{indent(string).inspect});"
|
53
|
+
end
|
54
|
+
|
55
|
+
def precompile_handlebars(string)
|
56
|
+
Barber::FilePrecompiler.call(string)
|
57
|
+
end
|
58
|
+
|
59
|
+
def compile_ember_handlebars(string)
|
60
|
+
"Hanber.Handlebars.compile(#{indent(string).inspect});"
|
61
|
+
end
|
62
|
+
|
63
|
+
def precompile_ember_handlebars(string)
|
64
|
+
Barber::Ember::FilePrecompiler.call(string)
|
65
|
+
end
|
66
|
+
|
67
|
+
def mustache_to_handlebars(scope, template)
|
68
|
+
if scope.pathname.to_s =~ /\.mustache\.(handlebars|hjs|hbs)/
|
69
|
+
template.gsub(/\{\{(\w[^\}\}]+)\}\}/){ |x| "{{unbound #{$1}}}" }
|
70
|
+
else
|
71
|
+
template
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def template_path(path)
|
76
|
+
root = configuration.templates_root
|
77
|
+
|
78
|
+
unless root.blank?
|
79
|
+
path.gsub!(/^#{Regexp.quote(root)}\/?/, '')
|
80
|
+
end
|
81
|
+
|
82
|
+
path = path.split('/')
|
83
|
+
|
84
|
+
path.join(configuration.templates_path_separator)
|
85
|
+
end
|
86
|
+
|
87
|
+
def configuration
|
88
|
+
::Rails.configuration.handlebars
|
89
|
+
end
|
90
|
+
|
91
|
+
def indent(string)
|
92
|
+
string.gsub(/$(.)/m, "\\1 ").strip
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'hanber/handlebars/template'
|
2
|
+
require 'active_model_serializers'
|
3
|
+
|
4
|
+
module Hanber
|
5
|
+
module Rails
|
6
|
+
class Engine < ::Rails::Engine
|
7
|
+
config.handlebars = ActiveSupport::OrderedOptions.new
|
8
|
+
|
9
|
+
config.handlebars.precompile = true
|
10
|
+
config.handlebars.templates_root = "templates"
|
11
|
+
config.handlebars.templates_path_separator = '/'
|
12
|
+
|
13
|
+
initializer "ember_rails.setup", :group => :all do |app|
|
14
|
+
|
15
|
+
app.assets.register_engine '.handlebars', Ember::Handlebars::Template
|
16
|
+
app.assets.register_engine '.hbs', Ember::Handlebars::Template
|
17
|
+
app.assets.register_engine '.hjs', Ember::Handlebars::Template
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/hanber-rails.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'hanber_rails'
|
data/lib/hanber_rails.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'rails'
|
2
|
+
require 'hanber/rails/version'
|
3
|
+
require 'hanber/version'
|
4
|
+
require 'hanber/handlebars/version'
|
5
|
+
require 'hanber/rails/engine'
|
6
|
+
|
7
|
+
module Hanber
|
8
|
+
module Rails
|
9
|
+
class Railtie < ::Rails::Railtie
|
10
|
+
config.ember = ActiveSupport::OrderedOptions.new
|
11
|
+
|
12
|
+
generators do |app|
|
13
|
+
app ||= ::Rails.application # Rails 3.0.x does not yield `app`
|
14
|
+
|
15
|
+
app.config.generators.assets = false
|
16
|
+
|
17
|
+
::Rails::Generators.configure!(app.config.generators)
|
18
|
+
::Rails::Generators.hidden_namespaces.uniq!
|
19
|
+
require "generators/hanber/resource_override"
|
20
|
+
end
|
21
|
+
|
22
|
+
initializer "ember_rails.setup_vendor", :after => "ember_rails.setup", :group => :all do |app|
|
23
|
+
if variant = app.config.ember.variant
|
24
|
+
# Add the gem's vendored ember to the end of the asset search path
|
25
|
+
ember_path = File.expand_path("../../vendor/ember/#{variant}", __FILE__)
|
26
|
+
app.config.assets.paths.push(ember_path.to_s)
|
27
|
+
|
28
|
+
# Allow a local variant override
|
29
|
+
ember_path = app.root.join("vendor/assets/ember/#{variant}")
|
30
|
+
app.config.assets.paths.unshift(ember_path.to_s) if ember_path.exist?
|
31
|
+
else
|
32
|
+
warn "No ember.js variant was specified in your config environment."
|
33
|
+
warn "You can set a specific variant in your application config in "
|
34
|
+
warn "order for sprockets to locate ember's assets:"
|
35
|
+
warn ""
|
36
|
+
warn " config.ember.variant = :development"
|
37
|
+
warn ""
|
38
|
+
warn "Valid values are :development and :production"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
initializer "ember_rails.find_ember", :after => "ember_rails.setup_vendor", :group => :all do |app|
|
43
|
+
config.ember.ember_location ||= location_for(app, "ember.js")
|
44
|
+
config.ember.handlebars_location ||= location_for(app, "handlebars.js")
|
45
|
+
end
|
46
|
+
|
47
|
+
initializer "ember_rails.es5_default", :group => :all do |app|
|
48
|
+
if defined?(Closure::Compiler) && app.config.assets.js_compressor == :closure
|
49
|
+
Closure::Compiler::DEFAULT_OPTIONS[:language_in] = 'ECMASCRIPT5'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def location_for(app, file)
|
54
|
+
path = app.config.assets.paths.find do |dir|
|
55
|
+
Pathname.new(dir).join(file).exist?
|
56
|
+
end
|
57
|
+
|
58
|
+
File.join(path, file) if path
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
metadata
ADDED
@@ -0,0 +1,197 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hanber-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.8
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- logical42
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-01-03 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: execjs
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.2'
|
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: '1.2'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: railties
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '3.1'
|
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: '3.1'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: active_model_serializers
|
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: barber
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :runtime
|
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
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: bundler
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 1.2.2
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 1.2.2
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: appraisal
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: tzinfo
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
description: ! ' hacked version of ember-rails '
|
127
|
+
email:
|
128
|
+
- han@thirstlabs.com
|
129
|
+
executables: []
|
130
|
+
extensions: []
|
131
|
+
extra_rdoc_files: []
|
132
|
+
files:
|
133
|
+
- .DS_Store
|
134
|
+
- .gitignore
|
135
|
+
- Appraisals
|
136
|
+
- Gemfile
|
137
|
+
- LICENSE.txt
|
138
|
+
- README.md
|
139
|
+
- Rakefile
|
140
|
+
- hanber-rails.gemspec
|
141
|
+
- lib/.DS_Store
|
142
|
+
- lib/generators/.DS_Store
|
143
|
+
- lib/generators/hanber/.DS_Store
|
144
|
+
- lib/generators/hanber/bootstrap_generator.rb
|
145
|
+
- lib/generators/hanber/controller_generator.rb
|
146
|
+
- lib/generators/hanber/generator_helpers.rb
|
147
|
+
- lib/generators/hanber/install_generator.rb
|
148
|
+
- lib/generators/hanber/model_generator.rb
|
149
|
+
- lib/generators/hanber/resource_override.rb
|
150
|
+
- lib/generators/hanber/route_handler_generator.rb
|
151
|
+
- lib/generators/hanber/scaffold_generator.rb
|
152
|
+
- lib/generators/hanber/view_generator.rb
|
153
|
+
- lib/generators/templates/app.js
|
154
|
+
- lib/generators/templates/application.handlebars
|
155
|
+
- lib/generators/templates/array_controller.js
|
156
|
+
- lib/generators/templates/controller.js
|
157
|
+
- lib/generators/templates/model.js
|
158
|
+
- lib/generators/templates/object_controller.js
|
159
|
+
- lib/generators/templates/route_handler.js
|
160
|
+
- lib/generators/templates/router.js
|
161
|
+
- lib/generators/templates/scaffolded_route.js
|
162
|
+
- lib/generators/templates/store.js
|
163
|
+
- lib/generators/templates/view.handlebars
|
164
|
+
- lib/generators/templates/view.js
|
165
|
+
- lib/hanber-rails.rb
|
166
|
+
- lib/hanber/.DS_Store
|
167
|
+
- lib/hanber/handlebars/template.rb
|
168
|
+
- lib/hanber/handlebars/version.rb
|
169
|
+
- lib/hanber/rails/engine.rb
|
170
|
+
- lib/hanber/rails/version.rb
|
171
|
+
- lib/hanber/version.rb
|
172
|
+
- lib/hanber_rails.rb
|
173
|
+
homepage: ''
|
174
|
+
licenses: []
|
175
|
+
post_install_message:
|
176
|
+
rdoc_options: []
|
177
|
+
require_paths:
|
178
|
+
- lib
|
179
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
180
|
+
none: false
|
181
|
+
requirements:
|
182
|
+
- - ! '>='
|
183
|
+
- !ruby/object:Gem::Version
|
184
|
+
version: '0'
|
185
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
186
|
+
none: false
|
187
|
+
requirements:
|
188
|
+
- - ! '>='
|
189
|
+
- !ruby/object:Gem::Version
|
190
|
+
version: '0'
|
191
|
+
requirements: []
|
192
|
+
rubyforge_project:
|
193
|
+
rubygems_version: 1.8.24
|
194
|
+
signing_key:
|
195
|
+
specification_version: 3
|
196
|
+
summary: customized version of ember-rails for me, han
|
197
|
+
test_files: []
|