slim-rails 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Leonardo Almeida
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.rdoc ADDED
@@ -0,0 +1,17 @@
1
+ = slim-rails
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 Leonardo Almeida. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,52 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require File.expand_path("../lib/slim-rails/version", __FILE__)
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "slim-rails"
8
+ gem.version = Slim::Rails::VERSION
9
+ gem.summary = "Provides generators for Rails 3"
10
+ gem.description = "Provide generators for Rails 3"
11
+ gem.email = "lalmeida08@gmail.com"
12
+ gem.homepage = "http://github.com/leogalmeida/slim-rails"
13
+ gem.authors = ["Leonardo Almeida"]
14
+ end
15
+ Jeweler::GemcutterTasks.new
16
+ rescue LoadError
17
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
18
+ end
19
+
20
+ require 'rake/testtask'
21
+ Rake::TestTask.new(:test) do |test|
22
+ test.libs << 'lib' << 'test'
23
+ test.pattern = 'test/**/*_test.rb'
24
+ test.verbose = true
25
+ end
26
+
27
+ begin
28
+ require 'rcov/rcovtask'
29
+ Rcov::RcovTask.new do |test|
30
+ test.libs << 'test'
31
+ test.pattern = 'test/**/*_test.rb'
32
+ test.verbose = true
33
+ end
34
+ rescue LoadError
35
+ task :rcov do
36
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
37
+ end
38
+ end
39
+
40
+ task :test => :check_dependencies
41
+
42
+ task :default => :test
43
+
44
+ require 'rake/rdoctask'
45
+ Rake::RDocTask.new do |rdoc|
46
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
47
+
48
+ rdoc.rdoc_dir = 'rdoc'
49
+ rdoc.title = "slim-rails #{version}"
50
+ rdoc.rdoc_files.include('README*')
51
+ rdoc.rdoc_files.include('lib/**/*.rb')
52
+ end
@@ -0,0 +1,16 @@
1
+ require 'rails/generators/erb/controller/controller_generator'
2
+
3
+ module Slim
4
+ module Generators
5
+ class ControllerGenerator < Erb::Generators::ControllerGenerator
6
+ source_root File.expand_path("../templates", __FILE__)
7
+
8
+ protected
9
+
10
+ def handler
11
+ :slim
12
+ end
13
+
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,2 @@
1
+ h1 <%= class_name %>#<%= @action %>
2
+ p Find me in <%= @path %>
@@ -0,0 +1,16 @@
1
+ require 'generators/slim/controller/controller_generator'
2
+
3
+ module Slim
4
+ module Generators
5
+ class MailerGenerator < ControllerGenerator
6
+ source_root File.expand_path("../templates", __FILE__)
7
+
8
+ protected
9
+
10
+ def format
11
+ :text
12
+ end
13
+
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ <%= class_name %>#<%= @action %>
2
+
3
+ = @greeting + ", find me in <%= @path %>"
@@ -0,0 +1,29 @@
1
+ require 'rails/generators/erb/scaffold/scaffold_generator'
2
+
3
+ module Slim
4
+ module Generators
5
+ class ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
6
+ source_root File.expand_path("../templates", __FILE__)
7
+
8
+ def copy_view_files
9
+ available_views.each do |view|
10
+ filename = filename_with_extensions(view)
11
+ template "#{view}.html.slim", File.join("app/views", controller_file_path, filename)
12
+ end
13
+ end
14
+
15
+ hook_for :form_builder, :as => :scaffold
16
+
17
+ protected
18
+
19
+ def available_views
20
+ %w(index edit show new _form)
21
+ end
22
+
23
+ def handler
24
+ :slim
25
+ end
26
+
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,15 @@
1
+ = form_for @<%= singular_table_name %> do |f|
2
+ -if @<%= singular_table_name %>.errors.any?
3
+ #error_explanation
4
+ h2 = "#{pluralize(@<%= singular_table_name %>.errors.count, "error")} prohibited this <%= singular_table_name %> from being saved:"
5
+ ul
6
+ - @<%= singular_table_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_table_name %>
2
+
3
+ = render 'form'
4
+
5
+ = link_to 'Show', @<%= singular_table_name %>
6
+ \|
7
+ = link_to 'Back', <%= index_helper %>_path
@@ -0,0 +1,23 @@
1
+ h1 Listing <%= plural_table_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_table_name %>.each do |<%= singular_table_name %>|
13
+ tr
14
+ <% for attribute in attributes -%>
15
+ td= <%= singular_table_name %>.<%= attribute.name %>
16
+ <% end -%>
17
+ td= link_to 'Show', <%= singular_table_name %>
18
+ td= link_to 'Edit', edit_<%= singular_table_name %>_path(<%= singular_table_name %>)
19
+ td= link_to 'Destroy', <%= singular_table_name %>, :confirm => 'Are you sure?', :method => :delete
20
+
21
+ br
22
+
23
+ = link_to 'New <%= human_name %>', new_<%= singular_table_name %>_path
@@ -0,0 +1,5 @@
1
+ h1 New <%= singular_table_name %>
2
+
3
+ = render 'form'
4
+
5
+ = link_to 'Back', <%= index_helper %>_path
@@ -0,0 +1,11 @@
1
+ p#notice = notice
2
+
3
+ <% for attribute in attributes -%>
4
+ p
5
+ b <%= attribute.human_name %>:
6
+ = @<%= singular_table_name %>.<%= attribute.name %>
7
+ <% end -%>
8
+
9
+ = link_to 'Edit', edit_<%= singular_table_name %>_path(@<%= singular_table_name %>)
10
+ \|
11
+ = link_to 'Back', <%= index_helper %>_path
data/lib/slim-rails.rb ADDED
@@ -0,0 +1,14 @@
1
+ require 'rails'
2
+ require 'slim/rails'
3
+
4
+ module Slim
5
+ module Rails
6
+ class Railtie < ::Rails::Railtie
7
+ if ::Rails.version.to_f >= 3.1
8
+ config.app_generators.template_engine :slim
9
+ else
10
+ config.generators.template_engine :slim
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ module Slim
2
+ module Rails
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,71 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{slim-rails}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Leonardo Almeida"]
12
+ s.date = %q{2010-10-28}
13
+ s.description = %q{Provide generators for Rails 3}
14
+ s.email = %q{lalmeida08@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "lib/generators/slim/controller/controller_generator.rb",
26
+ "lib/generators/slim/controller/templates/view.html.slim",
27
+ "lib/generators/slim/mailer/mailer_generator.rb",
28
+ "lib/generators/slim/mailer/templates/view.text.slim",
29
+ "lib/generators/slim/scaffold/scaffold_generator.rb",
30
+ "lib/generators/slim/scaffold/templates/_form.html.slim",
31
+ "lib/generators/slim/scaffold/templates/edit.html.slim",
32
+ "lib/generators/slim/scaffold/templates/index.html.slim",
33
+ "lib/generators/slim/scaffold/templates/new.html.slim",
34
+ "lib/generators/slim/scaffold/templates/show.html.slim",
35
+ "lib/slim-rails.rb",
36
+ "lib/slim-rails/version.rb",
37
+ "slim-rails.gemspec",
38
+ "test/fixtures/routes.rb",
39
+ "test/lib/generators/slim/controller_generator_test.rb",
40
+ "test/lib/generators/slim/mailer_generator_test.rb",
41
+ "test/lib/generators/slim/scaffold_generator_test.rb",
42
+ "test/lib/generators/slim/testing_helper.rb",
43
+ "test/test_helper.rb",
44
+ "tmp/rails/config/routes.rb",
45
+ "tmp/rails/public/stylesheets/scaffold.css"
46
+ ]
47
+ s.homepage = %q{http://github.com/leogalmeida/slim-rails}
48
+ s.rdoc_options = ["--charset=UTF-8"]
49
+ s.require_paths = ["lib"]
50
+ s.rubygems_version = %q{1.3.7}
51
+ s.summary = %q{Provides generators for Rails 3}
52
+ s.test_files = [
53
+ "test/fixtures/routes.rb",
54
+ "test/lib/generators/slim/controller_generator_test.rb",
55
+ "test/lib/generators/slim/mailer_generator_test.rb",
56
+ "test/lib/generators/slim/scaffold_generator_test.rb",
57
+ "test/lib/generators/slim/testing_helper.rb",
58
+ "test/test_helper.rb"
59
+ ]
60
+
61
+ if s.respond_to? :specification_version then
62
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
63
+ s.specification_version = 3
64
+
65
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
66
+ else
67
+ end
68
+ else
69
+ end
70
+ end
71
+
@@ -0,0 +1,2 @@
1
+ TestApp.routes.draw do |map|
2
+ end
@@ -0,0 +1,17 @@
1
+ require 'test_helper'
2
+ require 'lib/generators/slim/testing_helper'
3
+
4
+ class Slim::Generators::ControllerGeneratorTest < Rails::Generators::TestCase
5
+ destination File.join(Rails.root)
6
+ tests Rails::Generators::ControllerGenerator
7
+ arguments %w(Account foo bar --template-engine slim)
8
+
9
+ setup :prepare_destination
10
+ setup :copy_routes
11
+
12
+ test "should invoke template engine" do
13
+ run_generator
14
+ assert_file "app/views/account/foo.html.slim", %r(app/views/account/foo\.html\.slim)
15
+ assert_file "app/views/account/bar.html.slim", %r(app/views/account/bar\.html\.slim)
16
+ end
17
+ end
@@ -0,0 +1,24 @@
1
+ require 'test_helper'
2
+ require 'lib/generators/slim/testing_helper'
3
+
4
+ class Slim::Generators::MailerGeneratorTest < Rails::Generators::TestCase
5
+ destination File.join(Rails.root)
6
+ tests Rails::Generators::MailerGenerator
7
+ arguments %w(notifier foo bar --template-engine slim)
8
+
9
+ setup :prepare_destination
10
+ setup :copy_routes
11
+
12
+ test "should invoke template engine" do
13
+ run_generator
14
+ assert_file "app/views/notifier/foo.text.slim" do |view|
15
+ assert_match %r(app/views/notifier/foo\.text\.slim), view
16
+ assert_match /\= @greeting/, view
17
+ end
18
+
19
+ assert_file "app/views/notifier/bar.text.slim" do |view|
20
+ assert_match %r(app/views/notifier/bar\.text\.slim), view
21
+ assert_match /\= @greeting/, view
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,26 @@
1
+ require 'test_helper'
2
+ require 'lib/generators/slim/testing_helper'
3
+
4
+ class Slim::Generators::ScaffoldGeneratorTest < Rails::Generators::TestCase
5
+ destination File.join(Rails.root)
6
+ tests Rails::Generators::ScaffoldGenerator
7
+ arguments %w(product_line title:string price:integer --template-engine slim)
8
+
9
+ setup :prepare_destination
10
+ setup :copy_routes
11
+
12
+ test "should invoke template engine" do
13
+ run_generator
14
+
15
+ %w(index edit new show _form).each { |view| assert_file "app/views/product_lines/#{view}.html.slim" }
16
+ assert_no_file "app/views/layouts/product_lines.html.slim"
17
+ end
18
+
19
+ test "should revoke template engine" do
20
+ run_generator
21
+ run_generator ["product_line"], :behavior => :revoke
22
+
23
+ assert_no_file "app/views/product_lines"
24
+ assert_no_file "app/views/layouts/product_lines.html.slim"
25
+ end
26
+ end
@@ -0,0 +1 @@
1
+ require_generators :slim => ['scaffold', 'controller', 'mailer']
@@ -0,0 +1,64 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'rails/all'
4
+ require 'rails/generators'
5
+ require 'rails/generators/test_case'
6
+
7
+ class TestApp < Rails::Application
8
+ config.root = File.dirname(__FILE__)
9
+ end
10
+ Rails.application = TestApp
11
+
12
+ module Rails
13
+ def self.root
14
+ @root ||= File.expand_path(File.join(File.dirname(__FILE__), '..', 'tmp', 'rails'))
15
+ end
16
+ end
17
+ Rails.application.config.root = Rails.root
18
+
19
+ Rails::Generators.configure!
20
+
21
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
22
+
23
+ def copy_routes
24
+ routes = File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', 'routes.rb'))
25
+ destination = File.join(Rails.root, "config")
26
+ FileUtils.mkdir_p(destination)
27
+ FileUtils.cp File.expand_path(routes), destination
28
+ end
29
+
30
+ def assert_class(klass, content)
31
+ assert content =~ /class #{klass}(\(.+\))?(.*?)\nend/m, "Expected to have class #{klass}"
32
+ yield $2.strip if block_given?
33
+ end
34
+
35
+ def generator_list
36
+ {
37
+ :rails => ['scaffold', 'controller', 'mailer'],
38
+ :slim => ['scaffold', 'controller', 'mailer']
39
+ }
40
+ end
41
+
42
+ def path_prefix(name)
43
+ case name
44
+ when :rails
45
+ 'rails/generators'
46
+ else
47
+ 'generators'
48
+ end
49
+ end
50
+
51
+ def require_generators(generator_list)
52
+ generator_list.each do |name, generators|
53
+ generators.each do |generator_name|
54
+ if name.to_s == 'rails' && generator_name.to_s == 'mailer'
55
+ require File.join(path_prefix(name), generator_name.to_s, "#{generator_name}_generator")
56
+ else
57
+ require File.join(path_prefix(name), name.to_s, generator_name.to_s, "#{generator_name}_generator")
58
+ end
59
+ end
60
+ end
61
+ end
62
+ alias :require_generator :require_generators
63
+
64
+ require_generators generator_list
@@ -0,0 +1,2 @@
1
+ TestApp.routes.draw do |map|
2
+ end
@@ -0,0 +1,56 @@
1
+ body { background-color: #fff; color: #333; }
2
+
3
+ body, p, ol, ul, td {
4
+ font-family: verdana, arial, helvetica, sans-serif;
5
+ font-size: 13px;
6
+ line-height: 18px;
7
+ }
8
+
9
+ pre {
10
+ background-color: #eee;
11
+ padding: 10px;
12
+ font-size: 11px;
13
+ }
14
+
15
+ a { color: #000; }
16
+ a:visited { color: #666; }
17
+ a:hover { color: #fff; background-color:#000; }
18
+
19
+ div.field, div.actions {
20
+ margin-bottom: 10px;
21
+ }
22
+
23
+ #notice {
24
+ color: green;
25
+ }
26
+
27
+ .field_with_errors {
28
+ padding: 2px;
29
+ background-color: red;
30
+ display: table;
31
+ }
32
+
33
+ #error_explanation {
34
+ width: 450px;
35
+ border: 2px solid red;
36
+ padding: 7px;
37
+ padding-bottom: 0;
38
+ margin-bottom: 20px;
39
+ background-color: #f0f0f0;
40
+ }
41
+
42
+ #error_explanation h2 {
43
+ text-align: left;
44
+ font-weight: bold;
45
+ padding: 5px 5px 5px 15px;
46
+ font-size: 12px;
47
+ margin: -7px;
48
+ margin-bottom: 0px;
49
+ background-color: #c00;
50
+ color: #fff;
51
+ }
52
+
53
+ #error_explanation ul li {
54
+ font-size: 12px;
55
+ list-style: square;
56
+ }
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: slim-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
+ - Leonardo Almeida
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-10-28 00:00:00 -02:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: Provide generators for Rails 3
22
+ email: lalmeida08@gmail.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files:
28
+ - LICENSE
29
+ - README.rdoc
30
+ files:
31
+ - .document
32
+ - .gitignore
33
+ - LICENSE
34
+ - README.rdoc
35
+ - Rakefile
36
+ - lib/generators/slim/controller/controller_generator.rb
37
+ - lib/generators/slim/controller/templates/view.html.slim
38
+ - lib/generators/slim/mailer/mailer_generator.rb
39
+ - lib/generators/slim/mailer/templates/view.text.slim
40
+ - lib/generators/slim/scaffold/scaffold_generator.rb
41
+ - lib/generators/slim/scaffold/templates/_form.html.slim
42
+ - lib/generators/slim/scaffold/templates/edit.html.slim
43
+ - lib/generators/slim/scaffold/templates/index.html.slim
44
+ - lib/generators/slim/scaffold/templates/new.html.slim
45
+ - lib/generators/slim/scaffold/templates/show.html.slim
46
+ - lib/slim-rails.rb
47
+ - lib/slim-rails/version.rb
48
+ - slim-rails.gemspec
49
+ - test/fixtures/routes.rb
50
+ - test/lib/generators/slim/controller_generator_test.rb
51
+ - test/lib/generators/slim/mailer_generator_test.rb
52
+ - test/lib/generators/slim/scaffold_generator_test.rb
53
+ - test/lib/generators/slim/testing_helper.rb
54
+ - test/test_helper.rb
55
+ - tmp/rails/config/routes.rb
56
+ - tmp/rails/public/stylesheets/scaffold.css
57
+ has_rdoc: true
58
+ homepage: http://github.com/leogalmeida/slim-rails
59
+ licenses: []
60
+
61
+ post_install_message:
62
+ rdoc_options:
63
+ - --charset=UTF-8
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ segments:
72
+ - 0
73
+ version: "0"
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ segments:
80
+ - 0
81
+ version: "0"
82
+ requirements: []
83
+
84
+ rubyforge_project:
85
+ rubygems_version: 1.3.7
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: Provides generators for Rails 3
89
+ test_files:
90
+ - test/fixtures/routes.rb
91
+ - test/lib/generators/slim/controller_generator_test.rb
92
+ - test/lib/generators/slim/mailer_generator_test.rb
93
+ - test/lib/generators/slim/scaffold_generator_test.rb
94
+ - test/lib/generators/slim/testing_helper.rb
95
+ - test/test_helper.rb