diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a1c5ed6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.redcar +pkg \ No newline at end of file diff --git a/CONTRIBUTORS b/CONTRIBUTORS new file mode 100644 index 0000000..e6f64b3 --- /dev/null +++ b/CONTRIBUTORS @@ -0,0 +1 @@ +Rafael Felix (felix.rafael@gmail.com) \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..8d3cfaa --- /dev/null +++ b/LICENSE @@ -0,0 +1,20 @@ +Copyright (c) 2009 Rafael Felix + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.markdown b/README.markdown index b563913..a7fdf86 100644 --- a/README.markdown +++ b/README.markdown @@ -13,13 +13,14 @@ Original idea from [Paul Barry's article on custom genrators][OriginalIdea] 1. Generate your new rails application: - rails ApplicationName + rails new ApplicationName cd ApplicationName -2. Edit "Gemfile" and add "gem haml" to the gem list +2. Edit "Gemfile" and add "gem haml" and "gem haml_rails" to the gem list 3. Either gem install haml + gem install haml_rails ...or... @@ -27,30 +28,15 @@ Original idea from [Paul Barry's article on custom genrators][OriginalIdea] 4. Run - haml --rails . - -5. Edit config/application.rb and add the following: - - config.generators do |g| - g.template_engine :haml - end - - -6. Either - - git clone git://github.com/psynix/rails3_haml_scaffold_generator.git lib/generators/haml - - ...or... - - git submodule add git://github.com/psynix/rails3_haml_scaffold_generator.git lib/generators/haml + rails generate haml_rails:install -7. Create stuff with: +5. Create stuff with: rails generate controller ControllerName index rails generate mailer ExamplesNotifications rails generate scaffold FancyModel - ... or if you like to mix it up with ERB, ignore step 5 and use ... + ... or if you like to mix it up with ERB, ignore step 4 and use ... rails generate haml:controller ControllerName index rails generate haml:mailer ExamplesNotifications @@ -58,6 +44,7 @@ Original idea from [Paul Barry's article on custom genrators][OriginalIdea] ## TODO -* Gemify (?) +* RSpec it (?) +* Add Contributors at the CONTRIBUTORS file [OriginalIdea]: http://paulbarry.com/articles/2010/01/13/customizing-generators-in-rails-3 diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..01ce823 --- /dev/null +++ b/Rakefile @@ -0,0 +1,48 @@ +require 'rubygems' +require 'rake' +require 'lib/version' + +begin + require 'jeweler' + Jeweler::Tasks.new do |gem| + gem.name = "haml_rails" + gem.summary = %Q{HAML scaffold template engine} + gem.description = %Q{HAML scaffold template engine} + gem.email = "felix.rafael@gmail.com" + gem.homepage = "http://github.com/fellix/haml_rails" + gem.authors = ["Rafael Felix"] + gem.add_development_dependency "rspec", ">= 1.2.9" + gem.version = HamlRails::Version::STRING + gem.files = FileList["[A-Z]*(.rdoc)", "{generators,lib}/**/*", "init.rb"] + # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings + end + Jeweler::GemcutterTasks.new +rescue LoadError + puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler" +end + +require 'spec/rake/spectask' +Spec::Rake::SpecTask.new(:spec) do |spec| + spec.libs << 'lib' << 'spec' + spec.spec_files = FileList['spec/**/*_spec.rb'] +end + +Spec::Rake::SpecTask.new(:rcov) do |spec| + spec.libs << 'lib' << 'spec' + spec.pattern = 'spec/**/*_spec.rb' + spec.rcov = true +end + +task :spec => :check_dependencies + +task :default => :spec + +require 'rake/rdoctask' +Rake::RDocTask.new do |rdoc| + version = File.exist?('VERSION') ? File.read('VERSION') : "" + + rdoc.rdoc_dir = 'rdoc' + rdoc.title = "haml_rails #{version}" + rdoc.rdoc_files.include('README*') + rdoc.rdoc_files.include('lib/**/*.rb') +end diff --git a/haml_rails.gemspec b/haml_rails.gemspec new file mode 100644 index 0000000..9d8761a --- /dev/null +++ b/haml_rails.gemspec @@ -0,0 +1,59 @@ +# Generated by jeweler +# DO NOT EDIT THIS FILE DIRECTLY +# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command +# -*- encoding: utf-8 -*- + +Gem::Specification.new do |s| + s.name = %q{haml_rails} + s.version = "0.1.0" + + s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= + s.authors = ["Rafael Felix"] + s.date = %q{2010-11-08} + s.description = %q{HAML scaffold template engine} + s.email = %q{felix.rafael@gmail.com} + s.extra_rdoc_files = [ + "LICENSE", + "README.markdown" + ] + s.files = [ + "init.rb", + "lib/generators/haml_rails/install_generator.rb", + "lib/generators/haml_rails/templates/base.rb", + "lib/generators/haml_rails/templates/controller/controller_generator.rb", + "lib/generators/haml_rails/templates/controller/templates/view.html.haml", + "lib/generators/haml_rails/templates/mailer/mailer_generator.rb", + "lib/generators/haml_rails/templates/mailer/templates/view.text.haml", + "lib/generators/haml_rails/templates/scaffold/scaffold_generator.rb", + "lib/generators/haml_rails/templates/scaffold/templates/_form.html.haml", + "lib/generators/haml_rails/templates/scaffold/templates/edit.html.haml", + "lib/generators/haml_rails/templates/scaffold/templates/index.html.haml", + "lib/generators/haml_rails/templates/scaffold/templates/layout.html.haml", + "lib/generators/haml_rails/templates/scaffold/templates/new.html.haml", + "lib/generators/haml_rails/templates/scaffold/templates/show.html.haml", + "lib/haml_rails.rb", + "lib/version.rb" + ] + s.homepage = %q{http://github.com/fellix/haml_rails} + s.rdoc_options = ["--charset=UTF-8"] + s.require_paths = ["lib"] + s.rubygems_version = %q{1.3.6} + s.summary = %q{HAML scaffold template engine} + s.test_files = [ + "spec/spec_helper.rb" + ] + + if s.respond_to? :specification_version then + current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION + s.specification_version = 3 + + if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then + s.add_development_dependency(%q, [">= 1.2.9"]) + else + s.add_dependency(%q, [">= 1.2.9"]) + end + else + s.add_dependency(%q, [">= 1.2.9"]) + end +end + diff --git a/init.rb b/init.rb new file mode 100644 index 0000000..eb1033f --- /dev/null +++ b/init.rb @@ -0,0 +1 @@ +require 'haml_rails' \ No newline at end of file diff --git a/lib/generators/haml_rails/install_generator.rb b/lib/generators/haml_rails/install_generator.rb new file mode 100644 index 0000000..7363ac8 --- /dev/null +++ b/lib/generators/haml_rails/install_generator.rb @@ -0,0 +1,36 @@ +module HamlRails + module Generators + class InstallGenerator < Rails::Generators::Base + desc "Copy the defaults template to the application" + source_root File.expand_path('../templates', __FILE__) + + def copy_controller_template + @haml_dir = "lib/generators/haml" + copy_file File.expand_path('../templates/controller/controller_generator.rb', __FILE__), "#{@haml_dir}/controller/controller_generator.rb" + copy_file File.expand_path('../templates/controller/templates/view.html.haml', __FILE__), "#{@haml_dir}/controller/templates/view.html.haml" + end + def copy_mailer_template + copy_file File.expand_path('../templates/mailer/mailer_generator.rb', __FILE__), "#{@haml_dir}/mailer/mailer_generator.rb" + copy_file File.expand_path('../templates/mailer/templates/view.text.haml', __FILE__), "#{@haml_dir}/mailer/templates/view.text.haml" + end + def copy_scaffold_template + copy_file File.expand_path('../templates/scaffold/scaffold_generator.rb', __FILE__), "#{@haml_dir}/scaffold/scaffold_generator.rb" + copy_file File.expand_path('../templates/scaffold/templates/_form.html.haml', __FILE__), "#{@haml_dir}/scaffold/templates/_form.html.haml" + copy_file File.expand_path('../templates/scaffold/templates/edit.html.haml', __FILE__), "#{@haml_dir}/scaffold/templates/edit.html.haml" + copy_file File.expand_path('../templates/scaffold/templates/index.html.haml', __FILE__), "#{@haml_dir}/scaffold/templates/index.html.haml" + copy_file File.expand_path('../templates/scaffold/templates/layout.html.haml', __FILE__), "#{@haml_dir}/scaffold/templates/layout.html.haml" + copy_file File.expand_path('../templates/scaffold/templates/new.html.haml', __FILE__), "#{@haml_dir}/scaffold/templates/new.html.haml" + copy_file File.expand_path('../templates/scaffold/templates/show.html.haml', __FILE__), "#{@haml_dir}/scaffold/templates/show.html.haml" + copy_file File.expand_path('../templates/scaffold/templates/_form.html.haml', __FILE__), "lib/templates/haml/scaffold/templates/_form.html.haml" + end + def copy_base_file + copy_file File.expand_path('../templates/base.rb', __FILE__), "#{@haml_dir}/base.rb" + end + def change_application_rb + inject_into_file "config/application.rb", :after => "class Application < Rails::Application\n" do + " config.generators do |g|\n g.template_engine :haml\n end\n" + end + end + end + end +end \ No newline at end of file diff --git a/base.rb b/lib/generators/haml_rails/templates/base.rb similarity index 100% rename from base.rb rename to lib/generators/haml_rails/templates/base.rb diff --git a/controller/controller_generator.rb b/lib/generators/haml_rails/templates/controller/controller_generator.rb similarity index 100% rename from controller/controller_generator.rb rename to lib/generators/haml_rails/templates/controller/controller_generator.rb diff --git a/controller/templates/view.html.haml b/lib/generators/haml_rails/templates/controller/templates/view.html.haml similarity index 100% rename from controller/templates/view.html.haml rename to lib/generators/haml_rails/templates/controller/templates/view.html.haml diff --git a/mailer/mailer_generator.rb b/lib/generators/haml_rails/templates/mailer/mailer_generator.rb similarity index 100% rename from mailer/mailer_generator.rb rename to lib/generators/haml_rails/templates/mailer/mailer_generator.rb diff --git a/mailer/templates/view.text.haml b/lib/generators/haml_rails/templates/mailer/templates/view.text.haml similarity index 100% rename from mailer/templates/view.text.haml rename to lib/generators/haml_rails/templates/mailer/templates/view.text.haml diff --git a/scaffold/scaffold_generator.rb b/lib/generators/haml_rails/templates/scaffold/scaffold_generator.rb similarity index 100% rename from scaffold/scaffold_generator.rb rename to lib/generators/haml_rails/templates/scaffold/scaffold_generator.rb diff --git a/scaffold/templates/_form.html.haml b/lib/generators/haml_rails/templates/scaffold/templates/_form.html.haml similarity index 100% rename from scaffold/templates/_form.html.haml rename to lib/generators/haml_rails/templates/scaffold/templates/_form.html.haml diff --git a/scaffold/templates/edit.html.haml b/lib/generators/haml_rails/templates/scaffold/templates/edit.html.haml similarity index 100% rename from scaffold/templates/edit.html.haml rename to lib/generators/haml_rails/templates/scaffold/templates/edit.html.haml diff --git a/scaffold/templates/index.html.haml b/lib/generators/haml_rails/templates/scaffold/templates/index.html.haml similarity index 100% rename from scaffold/templates/index.html.haml rename to lib/generators/haml_rails/templates/scaffold/templates/index.html.haml diff --git a/scaffold/templates/layout.html.haml b/lib/generators/haml_rails/templates/scaffold/templates/layout.html.haml similarity index 100% rename from scaffold/templates/layout.html.haml rename to lib/generators/haml_rails/templates/scaffold/templates/layout.html.haml diff --git a/scaffold/templates/new.html.haml b/lib/generators/haml_rails/templates/scaffold/templates/new.html.haml similarity index 100% rename from scaffold/templates/new.html.haml rename to lib/generators/haml_rails/templates/scaffold/templates/new.html.haml diff --git a/scaffold/templates/show.html.haml b/lib/generators/haml_rails/templates/scaffold/templates/show.html.haml similarity index 100% rename from scaffold/templates/show.html.haml rename to lib/generators/haml_rails/templates/scaffold/templates/show.html.haml diff --git a/lib/haml_rails.rb b/lib/haml_rails.rb new file mode 100644 index 0000000..e69de29 diff --git a/lib/version.rb b/lib/version.rb new file mode 100644 index 0000000..c44117f --- /dev/null +++ b/lib/version.rb @@ -0,0 +1,9 @@ +module HamlRails + module Version + MAJOR = 0 + MINOR = 1 + PATCH = 0 + + STRING = [MAJOR, MINOR, PATCH].compact.join('.') + end +end \ No newline at end of file diff --git a/spec/spec.opts b/spec/spec.opts new file mode 100644 index 0000000..4e1e0d2 --- /dev/null +++ b/spec/spec.opts @@ -0,0 +1 @@ +--color diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..b32ab23 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,9 @@ +$LOAD_PATH.unshift(File.dirname(__FILE__)) +$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) +require 'haml_rails' +require 'spec' +require 'spec/autorun' + +Spec::Runner.configure do |config| + +end