tbh-scaffolds 0.0.1
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.
- data/.gitignore +6 -0
- data/Gemfile +4 -0
- data/Rakefile +1 -0
- data/lib/generators/haml/controller/controller_generator.rb +16 -0
- data/lib/generators/haml/controller/templates/view.html.haml +2 -0
- data/lib/generators/haml/mailer/mailer_generator.rb +16 -0
- data/lib/generators/haml/mailer/templates/view.text.haml +3 -0
- data/lib/generators/haml/scaffold/scaffold_generator.rb +36 -0
- data/lib/generators/haml/scaffold/templates/_form.html.haml +34 -0
- data/lib/generators/haml/scaffold/templates/edit.html.haml +4 -0
- data/lib/generators/haml/scaffold/templates/index.html.haml +26 -0
- data/lib/generators/haml/scaffold/templates/new.html.haml +4 -0
- data/lib/generators/haml/scaffold/templates/show.html.haml +13 -0
- data/lib/tbh-scaffolds.rb +23 -0
- data/lib/tbh-scaffolds/version.rb +5 -0
- data/tbh-scaffolds.gemspec +24 -0
- data/test/fixtures/routes.rb +58 -0
- data/test/lib/generators/haml/controller_generator_test.rb +17 -0
- data/test/lib/generators/haml/mailer_generator_test.rb +24 -0
- data/test/lib/generators/haml/scaffold_generator_test.rb +31 -0
- data/test/lib/generators/haml/testing_helper.rb +1 -0
- data/test/test_helper.rb +75 -0
- data/vendor/assets/javascripts/jquery.tablesorter.min.js +4 -0
- data/vendor/assets/javascripts/tbh-scaffolds.js.coffee +9 -0
- data/vendor/assets/stylesheets/bootstrap-1.2.0.css +1987 -0
- data/vendor/assets/stylesheets/tbh-scaffolds.css.scss +28 -0
- metadata +99 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rails/generators/erb/controller/controller_generator'
|
2
|
+
|
3
|
+
module Haml
|
4
|
+
module Generators
|
5
|
+
class ControllerGenerator < Erb::Generators::ControllerGenerator
|
6
|
+
source_root File.expand_path("../templates", __FILE__)
|
7
|
+
|
8
|
+
protected
|
9
|
+
|
10
|
+
def handler
|
11
|
+
:haml
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'generators/haml/controller/controller_generator'
|
2
|
+
|
3
|
+
module Haml
|
4
|
+
module Generators
|
5
|
+
class MailerGenerator < ControllerGenerator
|
6
|
+
source_root File.expand_path("../templates", __FILE__)
|
7
|
+
|
8
|
+
protected
|
9
|
+
|
10
|
+
def format
|
11
|
+
:text
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'rails/generators/erb/scaffold/scaffold_generator'
|
2
|
+
|
3
|
+
module Haml
|
4
|
+
module Generators
|
5
|
+
class ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
6
|
+
source_root File.expand_path("../templates", __FILE__)
|
7
|
+
|
8
|
+
def copy_view_files
|
9
|
+
available_views.each do |view|
|
10
|
+
filename = filename_with_extensions(view)
|
11
|
+
template "#{view}.html.haml", File.join("app/views", controller_file_path, filename)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
hook_for :form_builder, :as => :scaffold
|
16
|
+
|
17
|
+
def copy_form_file
|
18
|
+
if options[:form_builder].nil?
|
19
|
+
filename = filename_with_extensions("_form")
|
20
|
+
template "_form.html.haml", File.join("app/views", controller_file_path, filename)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
protected
|
25
|
+
|
26
|
+
def available_views
|
27
|
+
%w(index edit show new)
|
28
|
+
end
|
29
|
+
|
30
|
+
def handler
|
31
|
+
:haml
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
= form_for @<%= singular_table_name %> do |f|
|
2
|
+
|
3
|
+
<% attributes.each do |attribute| -%>
|
4
|
+
- if @<%= singular_table_name %>.errors[:<%= attribute.name %>].any?
|
5
|
+
.clearfix.error
|
6
|
+
= f.label :<%= attribute.name %>
|
7
|
+
.input
|
8
|
+
<% if [:date_select, :datetime_select, :time_select].include?(attribute.field_type) -%>
|
9
|
+
= f.<%= attribute.field_type %> :<%= attribute.name %>, {}, :class => 'small error'
|
10
|
+
<% elsif [:text_area].include?(attribute.field_type) -%>
|
11
|
+
= f.<%= attribute.field_type %> :<%= attribute.name %>, :class => 'xxlarge error'
|
12
|
+
<% else -%>
|
13
|
+
= f.<%= attribute.field_type %> :<%= attribute.name %>, :class => 'error'
|
14
|
+
<% end -%>
|
15
|
+
%span.help-inline
|
16
|
+
- @<%= singular_table_name %>.errors[:<%= attribute.name %>].each do |msg|
|
17
|
+
%p.error= msg
|
18
|
+
- else
|
19
|
+
.clearfix
|
20
|
+
= f.label :<%= attribute.name %>
|
21
|
+
.input
|
22
|
+
<% if [:date_select, :datetime_select, :time_select].include?(attribute.field_type) -%>
|
23
|
+
= f.<%= attribute.field_type %> :<%= attribute.name %>, {}, :class => 'small'
|
24
|
+
<% elsif [:text_area].include?(attribute.field_type) -%>
|
25
|
+
= f.<%= attribute.field_type %> :<%= attribute.name %>, :class => 'xxlarge'
|
26
|
+
<% else -%>
|
27
|
+
= f.<%= attribute.field_type %> :<%= attribute.name %>
|
28
|
+
<% end -%>
|
29
|
+
|
30
|
+
<% end -%>
|
31
|
+
|
32
|
+
.actions
|
33
|
+
= f.submit 'Save', :class => 'btn primary'
|
34
|
+
= link_to 'Back', <%= index_helper %>_path, :class => 'btn'
|
@@ -0,0 +1,26 @@
|
|
1
|
+
%h1 <%= plural_table_name.capitalize %>
|
2
|
+
|
3
|
+
%table.scaffold.common-table.zebra-stripped.sortable
|
4
|
+
%thead
|
5
|
+
%tr
|
6
|
+
<% for attribute in attributes -%>
|
7
|
+
%th <%= attribute.human_name %>
|
8
|
+
<% end -%>
|
9
|
+
%th.button_column
|
10
|
+
%th.button_column
|
11
|
+
%th.button_column
|
12
|
+
|
13
|
+
%tbody
|
14
|
+
- @<%= plural_table_name %>.each do |<%= singular_table_name %>|
|
15
|
+
%tr
|
16
|
+
<% for attribute in attributes -%>
|
17
|
+
%td= <%= singular_table_name %>.<%= attribute.name %>
|
18
|
+
<% end -%>
|
19
|
+
%td.button_column= link_to 'Show', <%= singular_table_name %>, :class => 'btn info float_left'
|
20
|
+
%td.button_column= link_to 'Edit', edit_<%= singular_table_name %>_path(<%= singular_table_name %>), :class => 'btn primary float_left'
|
21
|
+
%td.button_column= link_to 'Destroy', <%= singular_table_name %>, :confirm => 'Are you sure?', :method => :delete, :class => 'btn danger float_left'
|
22
|
+
|
23
|
+
%br
|
24
|
+
|
25
|
+
.actions
|
26
|
+
= link_to 'New <%= human_name %>', new_<%= singular_table_name %>_path, :class => 'btn primary '
|
@@ -0,0 +1,13 @@
|
|
1
|
+
- if notice
|
2
|
+
.alert-message.success
|
3
|
+
%a.close(href='#') x
|
4
|
+
%p= notice
|
5
|
+
|
6
|
+
<% for attribute in attributes -%>
|
7
|
+
%p
|
8
|
+
%b <%= attribute.human_name %>:
|
9
|
+
= @<%= singular_table_name %>.<%= attribute.name %>
|
10
|
+
<% end -%>
|
11
|
+
|
12
|
+
= link_to 'Edit', edit_<%= singular_table_name %>_path(@<%= singular_table_name %>), :class => 'btn primary'
|
13
|
+
= link_to 'Back', <%= index_helper %>_path, :class => 'btn'
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "tbh-scaffolds/version"
|
2
|
+
|
3
|
+
module Tbh
|
4
|
+
module Scaffolds
|
5
|
+
class Engine < ::Rails::Engine
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
module Rails
|
10
|
+
class Railtie < ::Rails::Railtie
|
11
|
+
if ::Rails.version.to_f >= 3.1
|
12
|
+
config.app_generators.template_engine :haml
|
13
|
+
else
|
14
|
+
config.generators.template_engine :haml
|
15
|
+
end
|
16
|
+
|
17
|
+
config.before_initialize do
|
18
|
+
Haml.init_rails(binding)
|
19
|
+
Haml::Template.options[:format] = :html5
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "tbh-scaffolds/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "tbh-scaffolds"
|
7
|
+
s.version = Tbh::Scaffolds::VERSION
|
8
|
+
s.authors = ["Max Gonzih"]
|
9
|
+
s.email = ["gonzih@gmail.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{Twitter Bootstrap Haml Scaffolds}
|
12
|
+
s.description = %q{Scaffolds templates based on Twitter Bootstrap framework}
|
13
|
+
|
14
|
+
s.rubyforge_project = "tbh-scaffolds"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
s.add_development_dependency "rake"
|
23
|
+
s.add_runtime_dependency "haml"
|
24
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
TestApp.routes.draw do |map|
|
2
|
+
# The priority is based upon order of creation:
|
3
|
+
# first created -> highest priority.
|
4
|
+
|
5
|
+
# Sample of regular route:
|
6
|
+
# match 'products/:id' => 'catalog#view'
|
7
|
+
# Keep in mind you can assign values other than :controller and :action
|
8
|
+
|
9
|
+
# Sample of named route:
|
10
|
+
# match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
|
11
|
+
# This route can be invoked with purchase_url(:id => product.id)
|
12
|
+
|
13
|
+
# Sample resource route (maps HTTP verbs to controller actions automatically):
|
14
|
+
# resources :products
|
15
|
+
|
16
|
+
# Sample resource route with options:
|
17
|
+
# resources :products do
|
18
|
+
# member do
|
19
|
+
# get :short
|
20
|
+
# post :toggle
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
# collection do
|
24
|
+
# get :sold
|
25
|
+
# end
|
26
|
+
# end
|
27
|
+
|
28
|
+
# Sample resource route with sub-resources:
|
29
|
+
# resources :products do
|
30
|
+
# resources :comments, :sales
|
31
|
+
# resource :seller
|
32
|
+
# end
|
33
|
+
|
34
|
+
# Sample resource route with more complex sub-resources
|
35
|
+
# resources :products do
|
36
|
+
# resources :comments
|
37
|
+
# resources :sales do
|
38
|
+
# get :recent, :on => :collection
|
39
|
+
# end
|
40
|
+
# end
|
41
|
+
|
42
|
+
# Sample resource route within a namespace:
|
43
|
+
# namespace :admin do
|
44
|
+
# # Directs /admin/products/* to Admin::ProductsController
|
45
|
+
# # (app/controllers/admin/products_controller.rb)
|
46
|
+
# resources :products
|
47
|
+
# end
|
48
|
+
|
49
|
+
# You can have the root of your site routed with "root"
|
50
|
+
# just remember to delete public/index.html.
|
51
|
+
# root :to => "welcome#index"
|
52
|
+
|
53
|
+
# See how all your routes lay out with "rake routes"
|
54
|
+
|
55
|
+
# This is a legacy wild controller route that's not recommended for RESTful applications.
|
56
|
+
# Note: This route will make all actions in every controller accessible via GET requests.
|
57
|
+
# match ':controller(/:action(/:id(.:format)))'
|
58
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'lib/generators/haml/testing_helper'
|
3
|
+
|
4
|
+
class Haml::Generators::ControllerGeneratorTest < Rails::Generators::TestCase
|
5
|
+
destination File.join(Rails.root)
|
6
|
+
tests Rails::Generators::ControllerGenerator
|
7
|
+
arguments %w(Account foo bar --template-engine haml)
|
8
|
+
|
9
|
+
setup :prepare_destination
|
10
|
+
setup :copy_routes
|
11
|
+
|
12
|
+
test "should invoke template engine" do
|
13
|
+
run_generator
|
14
|
+
assert_file "app/views/account/foo.html.haml", %r(app/views/account/foo\.html\.haml)
|
15
|
+
assert_file "app/views/account/bar.html.haml", %r(app/views/account/bar\.html\.haml)
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'lib/generators/haml/testing_helper'
|
3
|
+
|
4
|
+
class Haml::Generators::MailerGeneratorTest < Rails::Generators::TestCase
|
5
|
+
destination File.join(Rails.root)
|
6
|
+
tests Rails::Generators::MailerGenerator
|
7
|
+
arguments %w(notifier foo bar --template-engine haml)
|
8
|
+
|
9
|
+
setup :prepare_destination
|
10
|
+
setup :copy_routes
|
11
|
+
|
12
|
+
test "should invoke template engine" do
|
13
|
+
run_generator
|
14
|
+
assert_file "app/views/notifier/foo.text.haml" do |view|
|
15
|
+
assert_match %r(app/views/notifier/foo\.text\.haml), view
|
16
|
+
assert_match /\= @greeting/, view
|
17
|
+
end
|
18
|
+
|
19
|
+
assert_file "app/views/notifier/bar.text.haml" do |view|
|
20
|
+
assert_match %r(app/views/notifier/bar\.text\.haml), view
|
21
|
+
assert_match /\= @greeting/, view
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'lib/generators/haml/testing_helper'
|
3
|
+
|
4
|
+
class Haml::Generators::ScaffoldGeneratorTest < Rails::Generators::TestCase
|
5
|
+
destination File.join(Rails.root)
|
6
|
+
tests Rails::Generators::ScaffoldGenerator
|
7
|
+
arguments %w(product_line title:string price:integer --template-engine haml)
|
8
|
+
|
9
|
+
setup :prepare_destination
|
10
|
+
setup :copy_routes
|
11
|
+
|
12
|
+
test "should invoke template engine" do
|
13
|
+
run_generator
|
14
|
+
|
15
|
+
%w(index edit new show _form).each { |view| assert_file "app/views/product_lines/#{view}.html.haml" }
|
16
|
+
assert_no_file "app/views/layouts/product_lines.html.haml"
|
17
|
+
end
|
18
|
+
|
19
|
+
test "should revoke template engine" do
|
20
|
+
run_generator
|
21
|
+
run_generator ["product_line"], :behavior => :revoke
|
22
|
+
|
23
|
+
assert_no_file "app/views/product_lines"
|
24
|
+
assert_no_file "app/views/layouts/product_lines.html.haml"
|
25
|
+
end
|
26
|
+
|
27
|
+
test "should invoke form builder" do
|
28
|
+
run_generator %w(product_line title:string price:integer --template-engine haml --form-builder some-form-builder)
|
29
|
+
assert_no_file "app/views/product_lines/_form.html.haml"
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require_generators :haml => ['scaffold', 'controller', 'mailer']
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'rails/all'
|
4
|
+
require 'rails/generators'
|
5
|
+
require 'rails/generators/test_case'
|
6
|
+
|
7
|
+
class TestApp < Rails::Application
|
8
|
+
config.root = File.dirname(__FILE__)
|
9
|
+
end
|
10
|
+
Rails.application = TestApp
|
11
|
+
|
12
|
+
module Rails
|
13
|
+
def self.root
|
14
|
+
@root ||= File.expand_path(File.join(File.dirname(__FILE__), '..', 'tmp', 'rails'))
|
15
|
+
end
|
16
|
+
end
|
17
|
+
Rails.application.config.root = Rails.root
|
18
|
+
|
19
|
+
# Call configure to load the settings from
|
20
|
+
# Rails.application.config.generators to Rails::Generators
|
21
|
+
Rails::Generators.configure!
|
22
|
+
|
23
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
24
|
+
|
25
|
+
def copy_routes
|
26
|
+
routes = File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', 'routes.rb'))
|
27
|
+
destination = File.join(Rails.root, "config")
|
28
|
+
FileUtils.mkdir_p(destination)
|
29
|
+
FileUtils.cp File.expand_path(routes), destination
|
30
|
+
end
|
31
|
+
|
32
|
+
# Asserts the given class exists in the given content. When a block is given,
|
33
|
+
# it yields the content of the class.
|
34
|
+
#
|
35
|
+
# assert_file "test/functional/accounts_controller_test.rb" do |controller_test|
|
36
|
+
# assert_class "AccountsControllerTest", controller_test do |klass|
|
37
|
+
# assert_match /context "index action"/, klass
|
38
|
+
# end
|
39
|
+
# end
|
40
|
+
#
|
41
|
+
def assert_class(klass, content)
|
42
|
+
assert content =~ /class #{klass}(\(.+\))?(.*?)\nend/m, "Expected to have class #{klass}"
|
43
|
+
yield $2.strip if block_given?
|
44
|
+
end
|
45
|
+
|
46
|
+
def generator_list
|
47
|
+
{
|
48
|
+
:rails => ['scaffold', 'controller', 'mailer'],
|
49
|
+
:haml => ['scaffold', 'controller', 'mailer']
|
50
|
+
}
|
51
|
+
end
|
52
|
+
|
53
|
+
def path_prefix(name)
|
54
|
+
case name
|
55
|
+
when :rails
|
56
|
+
'rails/generators'
|
57
|
+
else
|
58
|
+
'generators'
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def require_generators(generator_list)
|
63
|
+
generator_list.each do |name, generators|
|
64
|
+
generators.each do |generator_name|
|
65
|
+
if name.to_s == 'rails' && generator_name.to_s == 'mailer'
|
66
|
+
require File.join(path_prefix(name), generator_name.to_s, "#{generator_name}_generator")
|
67
|
+
else
|
68
|
+
require File.join(path_prefix(name), name.to_s, generator_name.to_s, "#{generator_name}_generator")
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
alias :require_generator :require_generators
|
74
|
+
|
75
|
+
require_generators generator_list
|