skinny_scaffold 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/generators/skinny_scaffold_generator.rb +68 -0
- data/lib/generators/template_methods.rb +29 -0
- data/lib/generators/templates/_form.html.erb +4 -0
- data/lib/generators/templates/controller.rb +49 -0
- data/lib/generators/templates/edit.html.erb +1 -0
- data/lib/generators/templates/helper.rb +32 -0
- data/lib/generators/templates/index.html.erb +6 -0
- data/lib/generators/templates/new.html.erb +1 -0
- data/lib/generators/templates/partials/default_table.html.erb +8 -0
- data/lib/generators/templates/partials/tabula_rasa_table.html.erb +2 -0
- data/lib/skinny_scaffold.rb +7 -0
- data/lib/skinny_scaffold/railtie.rb +10 -0
- data/lib/skinny_scaffold/version.rb +3 -0
- data/skinny_scaffold.gemspec +25 -0
- metadata +105 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 63760eceb87b6db41b55c158a50ed13e0ab5bcbe
|
4
|
+
data.tar.gz: 25c2e3fb1f06be62318edbe1c71bc5741a837f30
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: daf0e8a00f915d8896df39cc7d64d1672f1a950e28b13c079cf36b7721e8201149a10520e71e32fe56ffd22ab2fbf852758735879534d516863e8ac97f0c86d6
|
7
|
+
data.tar.gz: ecd5a01b7943f4cf95d72c460b7cb7b3ad7263467d52180553c769e662fa62e7603673ba2c8c2e38662c902a7d4fdebc4d858081b8bf4d236986d15216776abf
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 RSL
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Skinny Scaffold
|
2
|
+
|
3
|
+
Skinny scaffolds for Rails 4. Currently defaults to Haml but I may add ERB support eventually. Dunno.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'skinny_scaffold'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install skinny_scaffold
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
rails g skinny_scaffold Model ...
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require_relative 'template_methods.rb'
|
2
|
+
|
3
|
+
class SkinnyScaffoldGenerator < Rails::Generators::NamedBase
|
4
|
+
include Rails::Generators::ResourceHelpers
|
5
|
+
include TemplateMethods
|
6
|
+
|
7
|
+
source_root File.expand_path('../templates', __FILE__)
|
8
|
+
|
9
|
+
def initialize(*args)
|
10
|
+
super
|
11
|
+
end
|
12
|
+
|
13
|
+
def copy_controller_file
|
14
|
+
template 'controller.rb', controller_filename_with_path
|
15
|
+
end
|
16
|
+
|
17
|
+
def handle_helper_file
|
18
|
+
behavior == :invoke ? do_copy_helper_file : dont_remove_helper_file
|
19
|
+
end
|
20
|
+
|
21
|
+
def create_view_folder
|
22
|
+
empty_directory File.join('app/views', controller_file_path)
|
23
|
+
end
|
24
|
+
|
25
|
+
def copy_view_files
|
26
|
+
available_views.each do |view|
|
27
|
+
template view_filename_with_extensions(view, :erb),
|
28
|
+
File.join('app/views', controller_file_path, view_filename_with_extensions(view))
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
protected
|
33
|
+
|
34
|
+
def available_views
|
35
|
+
%w{index _form new edit}
|
36
|
+
end
|
37
|
+
|
38
|
+
def format
|
39
|
+
:html
|
40
|
+
end
|
41
|
+
|
42
|
+
def handler
|
43
|
+
:haml
|
44
|
+
end
|
45
|
+
|
46
|
+
def controller_filename_with_path
|
47
|
+
File.join('app/controllers', "#{controller_name}_controller.rb")
|
48
|
+
end
|
49
|
+
|
50
|
+
def view_filename_with_extensions(name, local_handler = handler)
|
51
|
+
[name, format, local_handler].compact.join('.')
|
52
|
+
end
|
53
|
+
|
54
|
+
def helper_filename_with_path
|
55
|
+
'app/helpers/skinny_scaffold_helper.rb'
|
56
|
+
end
|
57
|
+
|
58
|
+
def do_copy_helper_file
|
59
|
+
return if File.exists?(helper_filename_with_path)
|
60
|
+
say_status 'NOTE >>>', 'Helper file will only be created once and will need to be removed manually!', :yellow
|
61
|
+
copy_file 'helper.rb', helper_filename_with_path
|
62
|
+
end
|
63
|
+
|
64
|
+
def dont_remove_helper_file
|
65
|
+
return unless File.exists?(helper_filename_with_path)
|
66
|
+
say_status 'NOTE >>>', 'Helper file must be removed manually to prevent destruction of customizations!', :yellow
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# Namespacing methods used exclusively in templates just for clarity
|
2
|
+
module TemplateMethods
|
3
|
+
def form_builder_method
|
4
|
+
return 'simple_form_for' if defined?(SimpleForm)
|
5
|
+
'form_for'
|
6
|
+
end
|
7
|
+
|
8
|
+
def plural_instance_variable
|
9
|
+
"@#{plural_table_name}"
|
10
|
+
end
|
11
|
+
|
12
|
+
def singular_instance_variable
|
13
|
+
"@#{singular_table_name}"
|
14
|
+
end
|
15
|
+
|
16
|
+
def table
|
17
|
+
ERB.new(table_partial).result binding
|
18
|
+
end
|
19
|
+
|
20
|
+
def table_source
|
21
|
+
return 'tabula_rasa_table' if defined?(TabulaRasa)
|
22
|
+
'default_table'
|
23
|
+
end
|
24
|
+
|
25
|
+
def table_partial
|
26
|
+
filename = File.join(self.class.source_root, 'partials', "#{table_source}.html.erb")
|
27
|
+
File.read File.expand_path(filename)
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
<% module_namespacing do -%>
|
2
|
+
class <%= controller_class_name %>Controller < ApplicationController
|
3
|
+
before_action :set_<%= file_name %>, only: [:edit, :update, :destroy]
|
4
|
+
respond_to :html
|
5
|
+
|
6
|
+
def index
|
7
|
+
<%= plural_instance_variable %> = <%= class_name %>.all
|
8
|
+
respond_with <%= plural_instance_variable %>
|
9
|
+
end
|
10
|
+
|
11
|
+
def new
|
12
|
+
<%= singular_instance_variable %> = <%= class_name %>.new
|
13
|
+
respond_with <%= singular_instance_variable %>
|
14
|
+
end
|
15
|
+
|
16
|
+
def create
|
17
|
+
<%= singular_instance_variable %> = <%= class_name %>.create(<%= file_name %>_params)
|
18
|
+
respond_with <%= singular_instance_variable %>
|
19
|
+
end
|
20
|
+
|
21
|
+
def edit
|
22
|
+
# Render
|
23
|
+
end
|
24
|
+
|
25
|
+
def update
|
26
|
+
<%= singular_instance_variable %>.update <%= file_name %>_params
|
27
|
+
respond_with <%= singular_instance_variable %>
|
28
|
+
end
|
29
|
+
|
30
|
+
def destroy
|
31
|
+
<%= singular_instance_variable %>.destroy
|
32
|
+
respond_with <%= singular_instance_variable %>
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def set_<%= file_name %>
|
38
|
+
<%= singular_instance_variable %> = <%= class_name %>.find(params[:id])
|
39
|
+
end
|
40
|
+
|
41
|
+
def <%= file_name %>_params
|
42
|
+
params.require(:<%= file_name %>).permit <%= file_name %>_attributes_whitelist
|
43
|
+
end
|
44
|
+
|
45
|
+
def <%= file_name %>_attributes_whitelist
|
46
|
+
[]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
<% end -%>
|
@@ -0,0 +1 @@
|
|
1
|
+
= render 'form'
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module SkinnyScaffoldHelper
|
2
|
+
def skinny_scaffold_index_header(object)
|
3
|
+
content_tag skinny_scaffold_header_tag, skinny_scaffold_object_name(object) + ' List'
|
4
|
+
end
|
5
|
+
|
6
|
+
def skinny_scaffold_form_header(object)
|
7
|
+
object_name = skinny_scaffold_object_name(object)
|
8
|
+
text = object.new_record? ? "Add #{object_name}" : "Edit #{object_name}"
|
9
|
+
content_tag skinny_scaffold_header_tag, text
|
10
|
+
end
|
11
|
+
|
12
|
+
def skinny_scaffold_link_to_add(class_name)
|
13
|
+
link_to "Add #{klass.name.humanize}", [:new, klass.name.underscore]
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def skinny_scaffold_header_tag
|
19
|
+
:h2
|
20
|
+
end
|
21
|
+
|
22
|
+
def skinny_scaffold_object_name(object)
|
23
|
+
case object
|
24
|
+
when ActiveRecord::Relation
|
25
|
+
object.klass.table_name.humanize.titleize
|
26
|
+
when ActiveRecord::Base
|
27
|
+
object.class.name.humanize.titleize
|
28
|
+
else
|
29
|
+
raise "Cannot determine skinny_scaffold_object_name for #{object}: #{object.class}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
= render 'form'
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'skinny_scaffold/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "skinny_scaffold"
|
8
|
+
spec.version = SkinnyScaffold::VERSION
|
9
|
+
spec.authors = ["RSL"]
|
10
|
+
spec.email = ["sconds@gmail.com"]
|
11
|
+
spec.description = %q{Skinny scaffolds for Rails 4}
|
12
|
+
spec.summary = %q{Quick, Haml-based scaffolds for Rails 4. Opinionated out the arse.}
|
13
|
+
spec.homepage = "https://github.com/rsl/skinny_scaffold"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency 'haml', '> 4.0'
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: skinny_scaffold
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- RSL
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: haml
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Skinny scaffolds for Rails 4
|
56
|
+
email:
|
57
|
+
- sconds@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- lib/generators/skinny_scaffold_generator.rb
|
68
|
+
- lib/generators/template_methods.rb
|
69
|
+
- lib/generators/templates/_form.html.erb
|
70
|
+
- lib/generators/templates/controller.rb
|
71
|
+
- lib/generators/templates/edit.html.erb
|
72
|
+
- lib/generators/templates/helper.rb
|
73
|
+
- lib/generators/templates/index.html.erb
|
74
|
+
- lib/generators/templates/new.html.erb
|
75
|
+
- lib/generators/templates/partials/default_table.html.erb
|
76
|
+
- lib/generators/templates/partials/tabula_rasa_table.html.erb
|
77
|
+
- lib/skinny_scaffold.rb
|
78
|
+
- lib/skinny_scaffold/railtie.rb
|
79
|
+
- lib/skinny_scaffold/version.rb
|
80
|
+
- skinny_scaffold.gemspec
|
81
|
+
homepage: https://github.com/rsl/skinny_scaffold
|
82
|
+
licenses:
|
83
|
+
- MIT
|
84
|
+
metadata: {}
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
requirements: []
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 2.2.2
|
102
|
+
signing_key:
|
103
|
+
specification_version: 4
|
104
|
+
summary: Quick, Haml-based scaffolds for Rails 4. Opinionated out the arse.
|
105
|
+
test_files: []
|