haml-rails 0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,3 @@
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.
@@ -0,0 +1,9 @@
1
+ module Haml
2
+ module Generators
3
+ module TemplatePath
4
+ def source_root
5
+ @_haml_source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'haml', generator_name, 'templates'))
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,16 @@
1
+ require 'generators/haml'
2
+ require 'rails/generators/erb/controller/controller_generator'
3
+
4
+ module Haml
5
+ module Generators
6
+ class ControllerGenerator < Erb::Generators::ControllerGenerator
7
+ extend TemplatePath
8
+
9
+ protected
10
+
11
+ def handler
12
+ :haml
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,2 @@
1
+ %h1 <%= class_name %>#<%= @action %>
2
+ %p Find me in <%= @path %>
@@ -0,0 +1,14 @@
1
+ require 'generators/haml'
2
+
3
+ module Haml
4
+ module Generators
5
+ class InstallGenerator < Rails::Generators::Base
6
+ extend TemplatePath
7
+
8
+ def copy_initializer_files
9
+ template "config/initializers/haml.rb.tt", "config/initializers/haml.rb"
10
+ end
11
+
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,4 @@
1
+ # Load Haml and Sass.
2
+ Haml.init_rails(binding) if defined?(Haml)
3
+
4
+ Haml::Template.options[:format] = :html5
@@ -0,0 +1,43 @@
1
+ require 'generators/haml'
2
+ require 'rails/generators/erb/scaffold/scaffold_generator'
3
+
4
+ module Haml
5
+ module Generators
6
+ class ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
7
+ extend TemplatePath
8
+
9
+ def copy_view_files
10
+ views = available_views
11
+ views.delete("index") if options[:singleton]
12
+
13
+ views.each do |view|
14
+ filename = filename_with_extensions(view)
15
+ template template_filename_with_extensions(view), File.join("app/views", controller_file_path, filename)
16
+ end
17
+ end
18
+
19
+ hook_for :form_builder, :as => :scaffold
20
+
21
+ def copy_form_file
22
+ if options[:form_builder].nil?
23
+ filename = filename_with_extensions("_form")
24
+ template template_filename_with_extensions("_form"), File.join("app/views", controller_file_path, filename)
25
+ end
26
+ end
27
+
28
+ protected
29
+
30
+ def available_views
31
+ %w(index edit show new)
32
+ end
33
+
34
+ def handler
35
+ :haml
36
+ end
37
+
38
+ def template_filename_with_extensions(name)
39
+ [name, format, handler, :erb].compact.join(".")
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,15 @@
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 <%= singular_name %> 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
+ = f.<%= attribute.field_type %> :<%= attribute.name %>
13
+ <% end -%>
14
+ .actions
15
+ = f.submit 'Save'
@@ -0,0 +1,7 @@
1
+ %h1 Editing <%= singular_name %>
2
+
3
+ = render 'form'
4
+
5
+ = link_to 'Show', @<%= singular_name %>
6
+ \|
7
+ = link_to 'Back', <%= plural_name %>_path
@@ -0,0 +1,23 @@
1
+ %h1 Listing <%= plural_name %>
2
+
3
+ %table
4
+ %tr
5
+ <% for attribute in attributes -%>
6
+ %th <%= attribute.human_name %>
7
+ <% end -%>
8
+ %th
9
+ %th
10
+ %th
11
+
12
+ - @<%= plural_name %>.each do |<%= singular_name %>|
13
+ %tr
14
+ <% for attribute in attributes -%>
15
+ %td= <%= singular_name %>.<%= attribute.name %>
16
+ <% end -%>
17
+ %td= link_to 'Show', <%= singular_name %>
18
+ %td= link_to 'Edit', edit_<%= singular_name %>_path(<%= singular_name %>)
19
+ %td= link_to 'Destroy', <%= singular_name %>, :confirm => 'Are you sure?', :method => :delete
20
+
21
+ %br
22
+
23
+ = link_to 'New <%= singular_name %>', new_<%= singular_name %>_path
@@ -0,0 +1,5 @@
1
+ %h1 New <%= singular_name %>
2
+
3
+ = render 'form'
4
+
5
+ = link_to 'Back', <%= plural_name %>_path
@@ -0,0 +1,9 @@
1
+ <% for attribute in attributes -%>
2
+ %p
3
+ %b <%= attribute.human_name %>:
4
+ = @<%= singular_name %>.<%= attribute.name %>
5
+ <% end -%>
6
+
7
+ = link_to 'Edit', edit_<%= singular_name %>_path(@<%= singular_name %>)
8
+ \|
9
+ = link_to 'Back', <%= plural_name %>_path
data/lib/haml-rails.rb ADDED
@@ -0,0 +1,7 @@
1
+ module Haml
2
+ module Rails
3
+ class Railtie < ::Rails::Railtie
4
+ config.generators.template_engine :haml
5
+ end
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,76 @@
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
+ version: "0.1"
9
+ platform: ruby
10
+ authors:
11
+ - "Andr\xC3\xA9 Arko"
12
+ autorequire:
13
+ bindir: bin
14
+ cert_chain: []
15
+
16
+ date: 2010-08-13 00:00:00 -07:00
17
+ default_executable:
18
+ dependencies: []
19
+
20
+ 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.
21
+ email:
22
+ - andre@arko.net
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files: []
28
+
29
+ files:
30
+ - README.md
31
+ - lib/generators/haml.rb
32
+ - lib/generators/haml/controller/controller_generator.rb
33
+ - lib/generators/haml/controller/templates/view.html.haml
34
+ - lib/generators/haml/install/install_generator.rb
35
+ - lib/generators/haml/install/templates/config/initializers/haml.rb.tt
36
+ - lib/generators/haml/scaffold/scaffold_generator.rb
37
+ - lib/generators/haml/scaffold/templates/_form.html.haml.erb
38
+ - lib/generators/haml/scaffold/templates/edit.html.haml.erb
39
+ - lib/generators/haml/scaffold/templates/index.html.haml.erb
40
+ - lib/generators/haml/scaffold/templates/new.html.haml.erb
41
+ - lib/generators/haml/scaffold/templates/show.html.haml.erb
42
+ - lib/haml-rails.rb
43
+ has_rdoc: true
44
+ homepage: http://github.com/indirect/haml-rails
45
+ licenses: []
46
+
47
+ post_install_message:
48
+ rdoc_options: []
49
+
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ segments:
57
+ - 0
58
+ version: "0"
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ segments:
64
+ - 1
65
+ - 3
66
+ - 6
67
+ version: 1.3.6
68
+ requirements: []
69
+
70
+ rubyforge_project: haml-rails
71
+ rubygems_version: 1.3.6
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: let your Gemfile do the configuring
75
+ test_files: []
76
+