Permalink
Browse files

Merge pull request #53 from nashby/fix-issue-12

Add haml template
  • Loading branch information...
carlosantoniodasilva committed Oct 16, 2012
2 parents e76283d + d08ffb1 commit a82b3482db2446996b8fa340ff42d2fe1f9a787a
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)
View
@@ -4,4 +4,5 @@ gemspec
gem "rake"
gem "rdoc"
+gem 'railties'
gem "ruby-debug", :platform => :mri_18
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
@@ -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'
@@ -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'
@@ -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
@@ -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
@@ -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
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'

0 comments on commit a82b348

Please sign in to comment.