haml_rails 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.markdown +63 -0
- data/init.rb +1 -0
- data/lib/generators/haml_rails/install_generator.rb +36 -0
- data/lib/generators/haml_rails/templates/base.rb +15 -0
- data/lib/generators/haml_rails/templates/controller/controller_generator.rb +21 -0
- data/lib/generators/haml_rails/templates/controller/templates/view.html.haml +2 -0
- data/lib/generators/haml_rails/templates/mailer/mailer_generator.rb +20 -0
- data/lib/generators/haml_rails/templates/mailer/templates/view.text.haml +3 -0
- data/lib/generators/haml_rails/templates/scaffold/scaffold_generator.rb +50 -0
- data/lib/generators/haml_rails/templates/scaffold/templates/_form.html.haml +17 -0
- data/lib/generators/haml_rails/templates/scaffold/templates/edit.html.haml +5 -0
- data/lib/generators/haml_rails/templates/scaffold/templates/index.html.haml +20 -0
- data/lib/generators/haml_rails/templates/scaffold/templates/layout.html.haml +12 -0
- data/lib/generators/haml_rails/templates/scaffold/templates/new.html.haml +3 -0
- data/lib/generators/haml_rails/templates/scaffold/templates/show.html.haml +10 -0
- data/lib/haml_rails.rb +0 -0
- data/lib/version.rb +9 -0
- data/spec/spec_helper.rb +9 -0
- metadata +93 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Rafael Felix
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# Information about this fork
|
2
|
+
|
3
|
+
This for is no longer following the normal scaffolding layout of Rails.
|
4
|
+
It uses I18n backend for headings, model attributes names etc in it's views.
|
5
|
+
|
6
|
+
## Rails 3 HAML Scaffold Generator
|
7
|
+
|
8
|
+
Essentially just a copy of the Rails 3 ERB generator with HAML replacements for the templates.
|
9
|
+
|
10
|
+
Original idea from [Paul Barry's article on custom genrators][OriginalIdea]
|
11
|
+
|
12
|
+
### Installation
|
13
|
+
|
14
|
+
1. Generate your new rails application:
|
15
|
+
|
16
|
+
rails ApplicationName
|
17
|
+
cd ApplicationName
|
18
|
+
|
19
|
+
2. Edit "Gemfile" and add "gem haml" to the gem list
|
20
|
+
3. Either
|
21
|
+
|
22
|
+
gem install haml
|
23
|
+
|
24
|
+
...or...
|
25
|
+
|
26
|
+
bundle install
|
27
|
+
|
28
|
+
4. Run
|
29
|
+
|
30
|
+
haml --rails .
|
31
|
+
|
32
|
+
5. Edit config/application.rb and add the following:
|
33
|
+
|
34
|
+
config.generators do |g|
|
35
|
+
g.template_engine :haml
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
6. Either
|
40
|
+
|
41
|
+
git clone git://github.com/psynix/rails3_haml_scaffold_generator.git lib/generators/haml
|
42
|
+
|
43
|
+
...or...
|
44
|
+
|
45
|
+
git submodule add git://github.com/psynix/rails3_haml_scaffold_generator.git lib/generators/haml
|
46
|
+
|
47
|
+
7. Create stuff with:
|
48
|
+
|
49
|
+
rails generate controller ControllerName index
|
50
|
+
rails generate mailer ExamplesNotifications
|
51
|
+
rails generate scaffold FancyModel
|
52
|
+
|
53
|
+
... or if you like to mix it up with ERB, ignore step 5 and use ...
|
54
|
+
|
55
|
+
rails generate haml:controller ControllerName index
|
56
|
+
rails generate haml:mailer ExamplesNotifications
|
57
|
+
rails generate haml:scaffold FancyModel
|
58
|
+
|
59
|
+
## TODO
|
60
|
+
|
61
|
+
* Gemify (?)
|
62
|
+
|
63
|
+
[OriginalIdea]: http://paulbarry.com/articles/2010/01/13/customizing-generators-in-rails-3
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'haml_rails'
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module HamlRails
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
desc "Copy the defaults template to the application"
|
5
|
+
source_root File.expand_path('../templates', __FILE__)
|
6
|
+
|
7
|
+
def copy_controller_template
|
8
|
+
@haml_dir = "lib/generators/haml"
|
9
|
+
copy_file File.expand_path('../templates/controller/controller_generator.rb', __FILE__), "#{@haml_dir}/controller/controller_generator.rb"
|
10
|
+
copy_file File.expand_path('../templates/controller/templates/view.html.haml', __FILE__), "#{@haml_dir}/controller/templates/view.html.haml"
|
11
|
+
end
|
12
|
+
def copy_mailer_template
|
13
|
+
copy_file File.expand_path('../templates/mailer/mailer_generator.rb', __FILE__), "#{@haml_dir}/mailer/mailer_generator.rb"
|
14
|
+
copy_file File.expand_path('../templates/mailer/templates/view.text.haml', __FILE__), "#{@haml_dir}/mailer/templates/view.text.haml"
|
15
|
+
end
|
16
|
+
def copy_scaffold_template
|
17
|
+
copy_file File.expand_path('../templates/scaffold/scaffold_generator.rb', __FILE__), "#{@haml_dir}/scaffold/scaffold_generator.rb"
|
18
|
+
copy_file File.expand_path('../templates/scaffold/templates/_form.html.haml', __FILE__), "#{@haml_dir}/scaffold/templates/_form.html.haml"
|
19
|
+
copy_file File.expand_path('../templates/scaffold/templates/edit.html.haml', __FILE__), "#{@haml_dir}/scaffold/templates/edit.html.haml"
|
20
|
+
copy_file File.expand_path('../templates/scaffold/templates/index.html.haml', __FILE__), "#{@haml_dir}/scaffold/templates/index.html.haml"
|
21
|
+
copy_file File.expand_path('../templates/scaffold/templates/layout.html.haml', __FILE__), "#{@haml_dir}/scaffold/templates/layout.html.haml"
|
22
|
+
copy_file File.expand_path('../templates/scaffold/templates/new.html.haml', __FILE__), "#{@haml_dir}/scaffold/templates/new.html.haml"
|
23
|
+
copy_file File.expand_path('../templates/scaffold/templates/show.html.haml', __FILE__), "#{@haml_dir}/scaffold/templates/show.html.haml"
|
24
|
+
copy_file File.expand_path('../templates/scaffold/templates/_form.html.haml', __FILE__), "lib/templates/haml/scaffold/templates/_form.html.haml"
|
25
|
+
end
|
26
|
+
def copy_base_file
|
27
|
+
copy_file File.expand_path('../templates/base.rb', __FILE__), "#{@haml_dir}/base.rb"
|
28
|
+
end
|
29
|
+
def change_application_rb
|
30
|
+
inject_into_file "config/application.rb", :after => "class Application < Rails::Application\n" do
|
31
|
+
" config.generators do |g|\n g.template_engine :haml\n end\n"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rails/generators/named_base'
|
2
|
+
|
3
|
+
module Haml
|
4
|
+
module Generators
|
5
|
+
class Base < Rails::Generators::NamedBase
|
6
|
+
# Automatically sets the source root based on the class name.
|
7
|
+
#
|
8
|
+
def self.source_root
|
9
|
+
@_haml_source_root ||= begin
|
10
|
+
File.expand_path(File.join(File.dirname(__FILE__), generator_name, 'templates')) if generator_name
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'generators/haml/base.rb'
|
2
|
+
|
3
|
+
module Haml
|
4
|
+
module Generators
|
5
|
+
class ControllerGenerator < Haml::Generators::Base
|
6
|
+
argument :actions, :type => :array, :default => [], :banner => "action action"
|
7
|
+
|
8
|
+
def create_view_files
|
9
|
+
base_path = File.join("app/views", class_path, file_name)
|
10
|
+
empty_directory base_path
|
11
|
+
|
12
|
+
actions.each do |action|
|
13
|
+
@action = action
|
14
|
+
@path = File.join(base_path, "#{action}.html.haml")
|
15
|
+
|
16
|
+
template 'view.html.haml', @path
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'generators/haml/base.rb'
|
2
|
+
|
3
|
+
module Haml
|
4
|
+
module Generators
|
5
|
+
class MailerGenerator < Haml::Generators::Base
|
6
|
+
argument :actions, :type => :array, :default => [], :banner => "method method"
|
7
|
+
|
8
|
+
def create_view_folder
|
9
|
+
empty_directory File.join("app/views", file_path)
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_view_files
|
13
|
+
actions.each do |action|
|
14
|
+
@action, @path = action, File.join(file_path, action)
|
15
|
+
template "view.text.haml", File.join("app/views", "#{@path}.text.haml")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'generators/haml/base.rb'
|
2
|
+
require 'rails/generators/resource_helpers'
|
3
|
+
|
4
|
+
module Haml
|
5
|
+
module Generators
|
6
|
+
class ScaffoldGenerator < Haml::Generators::Base
|
7
|
+
include Rails::Generators::ResourceHelpers
|
8
|
+
|
9
|
+
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
|
10
|
+
|
11
|
+
class_option :layout, :type => :boolean
|
12
|
+
class_option :singleton, :type => :boolean, :desc => "Supply to skip index view"
|
13
|
+
|
14
|
+
def create_root_folder
|
15
|
+
empty_directory File.join("app/views", controller_file_path)
|
16
|
+
end
|
17
|
+
|
18
|
+
def copy_index_file
|
19
|
+
return if options[:singleton]
|
20
|
+
copy_view :index
|
21
|
+
end
|
22
|
+
|
23
|
+
def copy_edit_file
|
24
|
+
copy_view :edit
|
25
|
+
end
|
26
|
+
|
27
|
+
def copy_show_file
|
28
|
+
copy_view :show
|
29
|
+
end
|
30
|
+
|
31
|
+
def copy_new_file
|
32
|
+
copy_view :new
|
33
|
+
end
|
34
|
+
|
35
|
+
def copy_form_file
|
36
|
+
copy_view :_form
|
37
|
+
end
|
38
|
+
|
39
|
+
def copy_layout_file
|
40
|
+
return unless options[:layout]
|
41
|
+
template "layout.html.haml", File.join("app/views/layouts", controller_class_path, "#{controller_file_name}.html.haml")
|
42
|
+
end
|
43
|
+
|
44
|
+
protected
|
45
|
+
def copy_view(view)
|
46
|
+
template "#{view}.html.haml", File.join("app/views", controller_file_path, "#{view}.html.haml")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
= form_for(@<%= singular_name %>) do |f|
|
2
|
+
- if @<%= singular_name %>.errors.any?
|
3
|
+
#errorExplanation
|
4
|
+
%h2= "#{pluralize(@<%= singular_name %>.errors.count, 'error')} prohibited this user from being saved:"
|
5
|
+
%ul
|
6
|
+
- @<%= singular_name %>.errors.full_messages.each do |msg|
|
7
|
+
%li= msg
|
8
|
+
|
9
|
+
<% for attribute in attributes -%>
|
10
|
+
.field
|
11
|
+
= f.label :<%= attribute.name %>
|
12
|
+
%br
|
13
|
+
= f.<%= attribute.field_type %> :<%= attribute.name %>
|
14
|
+
<% end -%>
|
15
|
+
|
16
|
+
.actions
|
17
|
+
= f.submit
|
@@ -0,0 +1,20 @@
|
|
1
|
+
%h1= t('.title')
|
2
|
+
%p= link_to t('.new_<%= singular_name %>'), new_<%= singular_name %>_path
|
3
|
+
|
4
|
+
%table
|
5
|
+
%thead
|
6
|
+
%tr
|
7
|
+
<% for attribute in attributes -%>
|
8
|
+
%th= <%= class_name %>.human_attribute_name :<%= attribute.name %>
|
9
|
+
<% end -%>
|
10
|
+
%th{:colspan => 3}= t 'actions'
|
11
|
+
|
12
|
+
%tbody
|
13
|
+
- for <%= singular_name %> in @<%= plural_name %>
|
14
|
+
%tr{ :class => cycle(:odd, :even) }
|
15
|
+
<% for attribute in attributes -%>
|
16
|
+
%td= <%= singular_name %>.<%= attribute.name %>
|
17
|
+
<% end -%>
|
18
|
+
%td.action= link_to t('show'), <%= singular_name %>
|
19
|
+
%td.action= link_to t('edit'), edit_<%= singular_name %>_path(<%= singular_name %>)
|
20
|
+
%td.action= link_to t('destroy'), <%= singular_name %>, :confirm => t('are_you_sure'), :method => :delete
|
@@ -0,0 +1,10 @@
|
|
1
|
+
%h1= t '.title'
|
2
|
+
%p
|
3
|
+
= link_to t('back'), <%= plural_name %>_path
|
4
|
+
= link_to t('edit'), edit_<%= singular_name %>_path(@<%= singular_name %>)
|
5
|
+
|
6
|
+
%dl
|
7
|
+
<% for attribute in attributes -%>
|
8
|
+
%dt= <%= class_name %>.human_attribute_name :<%= attribute.name %>
|
9
|
+
%dd= @<%= singular_name %>.<%= attribute.name %>
|
10
|
+
<% end -%>
|
data/lib/haml_rails.rb
ADDED
File without changes
|
data/lib/version.rb
ADDED
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: haml_rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Rafael Felix
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-11-08 00:00:00 -02:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rspec
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 1
|
29
|
+
- 2
|
30
|
+
- 9
|
31
|
+
version: 1.2.9
|
32
|
+
type: :development
|
33
|
+
version_requirements: *id001
|
34
|
+
description: HAML scaffold template engine
|
35
|
+
email: felix.rafael@gmail.com
|
36
|
+
executables: []
|
37
|
+
|
38
|
+
extensions: []
|
39
|
+
|
40
|
+
extra_rdoc_files:
|
41
|
+
- LICENSE
|
42
|
+
- README.markdown
|
43
|
+
files:
|
44
|
+
- init.rb
|
45
|
+
- lib/generators/haml_rails/install_generator.rb
|
46
|
+
- lib/generators/haml_rails/templates/base.rb
|
47
|
+
- lib/generators/haml_rails/templates/controller/controller_generator.rb
|
48
|
+
- lib/generators/haml_rails/templates/controller/templates/view.html.haml
|
49
|
+
- lib/generators/haml_rails/templates/mailer/mailer_generator.rb
|
50
|
+
- lib/generators/haml_rails/templates/mailer/templates/view.text.haml
|
51
|
+
- lib/generators/haml_rails/templates/scaffold/scaffold_generator.rb
|
52
|
+
- lib/generators/haml_rails/templates/scaffold/templates/_form.html.haml
|
53
|
+
- lib/generators/haml_rails/templates/scaffold/templates/edit.html.haml
|
54
|
+
- lib/generators/haml_rails/templates/scaffold/templates/index.html.haml
|
55
|
+
- lib/generators/haml_rails/templates/scaffold/templates/layout.html.haml
|
56
|
+
- lib/generators/haml_rails/templates/scaffold/templates/new.html.haml
|
57
|
+
- lib/generators/haml_rails/templates/scaffold/templates/show.html.haml
|
58
|
+
- lib/haml_rails.rb
|
59
|
+
- lib/version.rb
|
60
|
+
- LICENSE
|
61
|
+
- README.markdown
|
62
|
+
has_rdoc: true
|
63
|
+
homepage: http://github.com/fellix/haml_rails
|
64
|
+
licenses: []
|
65
|
+
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options:
|
68
|
+
- --charset=UTF-8
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
segments:
|
76
|
+
- 0
|
77
|
+
version: "0"
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
segments:
|
83
|
+
- 0
|
84
|
+
version: "0"
|
85
|
+
requirements: []
|
86
|
+
|
87
|
+
rubyforge_project:
|
88
|
+
rubygems_version: 1.3.6
|
89
|
+
signing_key:
|
90
|
+
specification_version: 3
|
91
|
+
summary: HAML scaffold template engine
|
92
|
+
test_files:
|
93
|
+
- spec/spec_helper.rb
|