bootstrap-haml-rails 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ *.gem
2
+ tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source :gemcutter
2
+
3
+ # Specify your gem's dependencies in haml-rails.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,19 @@
1
+ # Haml-rails
2
+
3
+ Haml-rails provides Haml generators for Rails 3. It also enables Haml as the templating engine for you, so you don't have to screw around in your own application.rb when your Gemfile already clearly indicated what templating engine you have installed. Hurrah.
4
+
5
+ To use it, add this line to your Gemfile:
6
+
7
+ gem "haml-rails"
8
+
9
+ Pretty fancy, eh?
10
+
11
+ Once you've done that, any time you generate a controller or scaffold, you'll get Haml instead of ERB templates. On top of that, when your Rails application loads, Haml will be loaded and initialized completely automatically! The modern world is just so amazing.
12
+
13
+ ### Contributors
14
+
15
+ Haml generators originally from [rails3-generators](http://github.com/indirect/rails3-generators), and written by José Valim, André Arko, Paul Barry, Anuj Dutta, Louis T, and Chris Rhoden. Tests originally written by Louis T.
16
+
17
+ ### License
18
+
19
+ Ruby license or MIT license, take your pick.
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rake/testtask'
5
+ Rake::TestTask.new(:test) do |test|
6
+ test.libs << 'lib' << 'test'
7
+ test.pattern = 'test/**/*_test.rb'
8
+ test.verbose = true
9
+ end
10
+
11
+ task :default => :test
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path("../lib/haml-rails/version", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "bootstrap-haml-rails"
6
+ s.version = Haml::Rails::VERSION
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = ["André Arko"]
9
+ s.email = ["andre@arko.net"]
10
+ s.homepage = "http://github.com/indirect/haml-rails"
11
+ s.summary = "let your Gemfile do the configuring"
12
+ s.description = "Haml-rails provides Haml generators for Rails 3. It also enables Haml as the templating engine for you, so you don't have to screw around in your own application.rb when your Gemfile already clearly indicated what templating engine you have installed. Hurrah."
13
+
14
+ s.rubyforge_project = "haml-rails"
15
+ s.required_rubygems_version = ">= 1.3.6"
16
+
17
+ s.add_dependency "haml", "~> 3.1"
18
+ s.add_dependency "activesupport", "~> 3.0"
19
+ s.add_dependency "actionpack", "~> 3.0"
20
+ s.add_dependency "railties", "~> 3.0"
21
+
22
+ s.add_development_dependency "rails", "~> 3.0"
23
+ s.add_development_dependency "bundler", "~> 1.0.0"
24
+
25
+ s.files = `git ls-files`.split("\n")
26
+ s.executables = `git ls-files`.split("\n").select{|f| f =~ /^bin/}
27
+ s.require_path = 'lib'
28
+ end
@@ -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,2 @@
1
+ %h1 <%= class_name %>#<%= @action %>
2
+ %p Find me in <%= @path %>
@@ -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,3 @@
1
+ <%= class_name %>#<%= @action %>
2
+
3
+ = @greeting + ", find me in <%= @path %>"
@@ -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,10 @@
1
+ = simple_form_for(@<%= singular_table_name %>, :html => {:class => 'form-horizontal' }) do |f|
2
+ = f.error_notification
3
+
4
+ .form-inputs
5
+ <%- attributes.each do |attribute| -%>
6
+ = f.<%= attribute.reference? ? :association : :input %> :<%= attribute.name %>, input_html: { class: "span6" }, hint: ''
7
+ <%- end -%>
8
+
9
+ .form-actions
10
+ = f.button :submit
@@ -0,0 +1,8 @@
1
+ .well
2
+ %h1 Editing <%= singular_table_name %>
3
+
4
+ = render 'form'
5
+
6
+ = link_to 'Show', @<%= singular_table_name %>
7
+ \|
8
+ = link_to 'Back', <%= index_helper %>_path
@@ -0,0 +1,23 @@
1
+ .well
2
+ %h1 Listing <%= plural_table_name %>
3
+
4
+ %table.table.table-bordered.table-striped
5
+ %thead
6
+ %tr
7
+ <% for attribute in attributes -%>
8
+ %th <%= attribute.human_name %>
9
+ <% end -%>
10
+ %th Actions
11
+
12
+ %tbody
13
+ - @<%= plural_table_name %>.each do |<%= singular_table_name %>|
14
+ %tr
15
+ <% for attribute in attributes -%>
16
+ %td= <%= singular_table_name %>.<%= attribute.name %>
17
+ <% end -%>
18
+ %td
19
+ = link_to 'Show', <%= singular_table_name %>, :class => 'btn btn-mini'
20
+ = link_to 'Edit', edit_<%= singular_table_name %>_path(<%= singular_table_name %>), :class => 'btn btn-mini'
21
+ = link_to 'Destroy', <%= singular_table_name %>, :confirm => 'Are you sure?', :method => :delete, :class => 'btn btn-mini btn-danger'
22
+
23
+ = link_to 'New <%= human_name %>', new_<%= singular_table_name %>_path, :class => 'btn btn-primary'
@@ -0,0 +1,6 @@
1
+ .well
2
+ %h1 New <%= singular_table_name %>
3
+
4
+ = render 'form'
5
+
6
+ = link_to 'Back', <%= index_helper %>_path
@@ -0,0 +1,12 @@
1
+ %p#notice= notice
2
+
3
+ <% for attribute in attributes -%>
4
+ %p
5
+ %b <%= attribute.human_name %>:
6
+ = @<%= singular_table_name %>.<%= attribute.name %>
7
+ <% end -%>
8
+
9
+ .form-actions
10
+ = link_to 'Edit', edit_<%= singular_table_name %>_path(@<%= singular_table_name %>), :class => 'btn'
11
+
12
+ = link_to 'Back', <%= index_helper %>_path, :class => 'btn'
data/lib/haml-rails.rb ADDED
@@ -0,0 +1,19 @@
1
+ require 'haml'
2
+ require 'rails'
3
+
4
+ module Haml
5
+ module Rails
6
+ class Railtie < ::Rails::Railtie
7
+ if ::Rails.version.to_f >= 3.1
8
+ config.app_generators.template_engine :haml
9
+ else
10
+ config.generators.template_engine :haml
11
+ end
12
+
13
+ config.before_initialize do
14
+ Haml.init_rails(binding)
15
+ Haml::Template.options[:format] = :html5
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,5 @@
1
+ module Haml
2
+ module Rails
3
+ VERSION = "0.4.5"
4
+ end
5
+ 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']
@@ -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
metadata ADDED
@@ -0,0 +1,137 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bootstrap-haml-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.5
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - André Arko
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-04 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: haml
16
+ requirement: &70227091330100 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '3.1'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70227091330100
25
+ - !ruby/object:Gem::Dependency
26
+ name: activesupport
27
+ requirement: &70227091329580 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '3.0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70227091329580
36
+ - !ruby/object:Gem::Dependency
37
+ name: actionpack
38
+ requirement: &70227091329060 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: '3.0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70227091329060
47
+ - !ruby/object:Gem::Dependency
48
+ name: railties
49
+ requirement: &70227091328560 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *70227091328560
58
+ - !ruby/object:Gem::Dependency
59
+ name: rails
60
+ requirement: &70227091328080 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: '3.0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70227091328080
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: &70227091327580 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ version: 1.0.0
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70227091327580
80
+ description: Haml-rails provides Haml generators for Rails 3. It also enables Haml
81
+ as the templating engine for you, so you don't have to screw around in your own
82
+ application.rb when your Gemfile already clearly indicated what templating engine
83
+ you have installed. Hurrah.
84
+ email:
85
+ - andre@arko.net
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - Gemfile
92
+ - README.md
93
+ - Rakefile
94
+ - haml-rails.gemspec
95
+ - lib/generators/haml/controller/controller_generator.rb
96
+ - lib/generators/haml/controller/templates/view.html.haml
97
+ - lib/generators/haml/mailer/mailer_generator.rb
98
+ - lib/generators/haml/mailer/templates/view.text.haml
99
+ - lib/generators/haml/scaffold/scaffold_generator.rb
100
+ - lib/generators/haml/scaffold/templates/_form.html.haml
101
+ - lib/generators/haml/scaffold/templates/edit.html.haml
102
+ - lib/generators/haml/scaffold/templates/index.html.haml
103
+ - lib/generators/haml/scaffold/templates/new.html.haml
104
+ - lib/generators/haml/scaffold/templates/show.html.haml
105
+ - lib/haml-rails.rb
106
+ - lib/haml-rails/version.rb
107
+ - test/fixtures/routes.rb
108
+ - test/lib/generators/haml/controller_generator_test.rb
109
+ - test/lib/generators/haml/mailer_generator_test.rb
110
+ - test/lib/generators/haml/scaffold_generator_test.rb
111
+ - test/lib/generators/haml/testing_helper.rb
112
+ - test/test_helper.rb
113
+ homepage: http://github.com/indirect/haml-rails
114
+ licenses: []
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ none: false
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ none: false
127
+ requirements:
128
+ - - ! '>='
129
+ - !ruby/object:Gem::Version
130
+ version: 1.3.6
131
+ requirements: []
132
+ rubyforge_project: haml-rails
133
+ rubygems_version: 1.8.17
134
+ signing_key:
135
+ specification_version: 3
136
+ summary: let your Gemfile do the configuring
137
+ test_files: []