Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

add haml template #53

Merged
merged 1 commit into from

2 participants

Vasiliy Ermolovich Carlos Antonio da Silva
Vasiliy Ermolovich
Collaborator

No description provided.

Carlos Antonio da Silva
Collaborator

Looks good bro, can you please add a changelog entry? Thanks!

Carlos Antonio da Silva carlosantoniodasilva merged commit a82b348 into from
Carlos Antonio da Silva
Collaborator

Thank you :blue_heart::purple_heart::heart::yellow_heart::green_heart:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 16, 2012
  1. Vasiliy Ermolovich

    add haml template

    nashby authored
    closes #12
This page is out of date. Refresh to see the latest.
1  CHANGELOG.rdoc
View
@@ -1,6 +1,7 @@
== master
* enhancements
+ * Add Haml template. (by github.com/nashby) Closes #12.
* Add `blank_html` tanslation. (by github.com/nashby)
* Add `show_for_class` configuration option. (by github.com/nashby)
1  Gemfile
View
@@ -4,4 +4,5 @@ gemspec
gem "rake"
gem "rdoc"
+gem 'railties'
gem "ruby-debug", :platform => :mri_18
11 Gemfile.lock
View
@@ -37,8 +37,17 @@ GEM
rack (1.4.1)
rack-cache (1.2)
rack (>= 0.4)
+ rack-ssl (1.3.2)
+ rack
rack-test (0.6.1)
rack (>= 1.0)
+ railties (3.2.3)
+ actionpack (= 3.2.3)
+ activesupport (= 3.2.3)
+ rack-ssl (~> 1.3.2)
+ rake (>= 0.8.7)
+ rdoc (~> 3.4)
+ thor (~> 0.14.6)
rake (0.9.2.2)
rbx-require-relative (0.0.9)
rdoc (3.12)
@@ -52,12 +61,14 @@ GEM
hike (~> 1.2)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
+ thor (0.14.6)
tilt (1.3.3)
PLATFORMS
ruby
DEPENDENCIES
+ railties
rake
rdoc
ruby-debug
1  gemfiles/Gemfile-rails.3.0.x
View
@@ -5,3 +5,4 @@ gem "rdoc"
gem 'show_for', :path => '..'
gem 'activemodel', '~> 3.0.0'
gem 'actionpack', '~> 3.0.0'
+gem 'railties', '~> 3.0.0'
1  gemfiles/Gemfile-rails.3.1.x
View
@@ -5,3 +5,4 @@ gem "rdoc"
gem 'show_for', :path => '..'
gem 'activemodel', '~> 3.1.0'
gem 'actionpack', '~> 3.1.0'
+gem 'railties', '~> 3.1.0'
6 lib/generators/show_for/install_generator.rb
View
@@ -2,6 +2,7 @@ module ShowFor
module Generators
class InstallGenerator < Rails::Generators::Base
desc "Copy ShowFor installation files"
+ class_option :template_engine, :desc => 'Template engine to be invoked (erb or haml or slim).'
source_root File.expand_path('../templates', __FILE__)
def copy_initializers
@@ -13,8 +14,9 @@ def copy_locale_file
end
def copy_generator_template
- copy_file 'show.html.erb', 'lib/templates/erb/scaffold/show.html.erb'
+ engine = options[:template_engine]
+ copy_file "show.html.#{engine}", "lib/templates/#{engine}/scaffold/show.html.#{engine}"
end
end
end
-end
+end
8 lib/generators/show_for/templates/show.html.haml
View
@@ -0,0 +1,8 @@
+= show_for(@<%= singular_name %>) do |s|
+<%- attributes.each do |attribute| -%>
+ = s.<%= attribute.reference? ? :association : :attribute %> :<%= attribute.name %>
+<% end -%>
+
+= link_to 'Edit', edit_<%= singular_name %>_path(@<%= singular_name %>)
+|
+= link_to 'Back', <%= plural_name %>_path
26 test/generators/show_for_generator_test.rb
View
@@ -0,0 +1,26 @@
+require 'test_helper'
+
+class ShowForGeneratorTest < Rails::Generators::TestCase
+ tests ShowFor::Generators::InstallGenerator
+ destination File.expand_path('../../tmp', __FILE__)
+ setup :prepare_destination
+ teardown { rm_rf(destination_root) }
+
+ test 'generates example locale file' do
+ run_generator
+ assert_file 'config/locales/show_for.en.yml'
+ end
+
+ test 'generates the show_for initializer' do
+ run_generator
+ assert_file 'config/initializers/show_for.rb',
+ /config.show_for_tag = :div/
+ end
+
+ %W(erb haml).each do |engine|
+ test "generates the scaffold template when using #{engine}" do
+ run_generator ['-e', engine]
+ assert_file "lib/templates/#{engine}/scaffold/show.html.#{engine}"
+ end
+ end
+end
3  test/test_helper.rb
View
@@ -9,6 +9,9 @@
require 'action_view/template'
require 'action_view/test_case'
+require "rails/generators/test_case"
+require 'generators/show_for/install_generator'
+
$:.unshift File.expand_path("../../lib", __FILE__)
require 'show_for'
Something went wrong with that request. Please try again.