toy_scaffold 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7b1524baf8d4f35418856e30a1a165dd8c9e658a
4
+ data.tar.gz: cfcfcd8f31bafa4fcd05815d9710e38327ad2e7e
5
+ SHA512:
6
+ metadata.gz: 9128cf2140ee947dbfb23e534c0ff13e8c3d0c5403334275b71b35ef0dbba769d0ce29eeaffe30f0389da87b79a2758f20456335671d913b3705c35fc40af3db
7
+ data.tar.gz: 348b6b193d19559e3b5607836e7dc263e10c3c4d0eb3b07a437d37d977bad8f9a17d68e0cd4f3e322a293512389db8f924ff434182d97ab3828ce687ee876f87
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in toy_scaffold.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 lulalala
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.
@@ -0,0 +1,39 @@
1
+ # ToyScaffold
2
+
3
+ Having coached in both Rails Girls and Rails Bridge, I found that quite a few students are confused by all the magic happening behind Rails. This gem aims to make it easier to understand for beginners, especially those who are programming for the first time.
4
+
5
+ The changes include:
6
+
7
+ - Instead of loading models through `before_action`, explicitly loading in each action instead.
8
+ - Do not use `respond_to`, but just assume HTML instead.
9
+ - Comment about each action's respective view file path
10
+
11
+ ## Installation
12
+
13
+ Add this line to your Rails application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'toy_scaffold'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ ## Usage
24
+
25
+ When calling `rails generate scaffold Post`, the toy_scaffold version will be used automatically.
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it ( https://github.com/[my-github-username]/toy_scaffold/fork )
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "toy_scaffold"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,78 @@
1
+ <% if namespaced? -%>
2
+ require_dependency "<%= namespaced_file_path %>/application_controller"
3
+
4
+ <% end -%>
5
+ <% module_namespacing do -%>
6
+ # This is generated using toy_scaffold,
7
+ # and is meant for learning purposes only.
8
+ # It aims for more clarity for beginners, therefore
9
+ # sacrifices some best practices and DRY principle.
10
+
11
+ class <%= controller_class_name %>Controller < ApplicationController
12
+ # GET <%= route_url %>
13
+ # View file is at app/views/<%= plural_table_name %>/index.html.erb
14
+ def index
15
+ @<%= plural_table_name %> = <%= orm_class.all(class_name) %>
16
+ end
17
+
18
+ # GET <%= route_url %>/1
19
+ # View file is at app/views/<%= plural_table_name %>/show.html.erb
20
+ def show
21
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
22
+ end
23
+
24
+ # GET <%= route_url %>/new
25
+ # View file is at app/views/<%= plural_table_name %>/new.html.erb
26
+ def new
27
+ @<%= singular_table_name %> = <%= orm_class.build(class_name) %>
28
+ end
29
+
30
+ # GET <%= route_url %>/1/edit
31
+ # View file is at app/views/<%= plural_table_name %>/edit.html.erb
32
+ def edit
33
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
34
+ end
35
+
36
+ # POST <%= route_url %>
37
+ def create
38
+ @<%= singular_table_name %> = <%= orm_class.build(class_name, "#{singular_table_name}_params") %>
39
+
40
+ if @<%= orm_instance.save %>
41
+ redirect_to @<%= singular_table_name %>, notice: <%= "'#{human_name} was successfully created.'" %>
42
+ else
43
+ render :new
44
+ end
45
+ end
46
+
47
+ # PATCH/PUT <%= route_url %>/1
48
+ def update
49
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
50
+
51
+ if @<%= orm_instance.update("#{singular_table_name}_params") %>
52
+ redirect_to @<%= singular_table_name %>, notice: <%= "'#{human_name} was successfully updated.'" %>
53
+ else
54
+ render :edit
55
+ end
56
+ end
57
+
58
+ # DELETE <%= route_url %>/1
59
+ def destroy
60
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
61
+
62
+ @<%= orm_instance.destroy %>
63
+ redirect_to <%= index_helper %>_url, notice: <%= "'#{human_name} was successfully destroyed.'" %>
64
+ end
65
+
66
+ private
67
+
68
+ # Only allow a trusted parameter "white list" through.
69
+ def <%= "#{singular_table_name}_params" %>
70
+ <%- if attributes_names.empty? -%>
71
+ params[:<%= singular_table_name %>]
72
+ <%- else -%>
73
+ params.require(:<%= singular_table_name %>).permit(<%= attributes_names.map { |name| ":#{name}" }.join(', ') %>)
74
+ <%- end -%>
75
+ end
76
+ end
77
+ <% end -%>
78
+
@@ -0,0 +1,9 @@
1
+ require "toy_scaffold/version"
2
+
3
+ module ToyScaffold
4
+ class Railtie < Rails::Railtie
5
+ config.app_generators do |g|
6
+ g.templates.unshift File::expand_path('../templates', __FILE__)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module ToyScaffold
2
+ VERSION = "0.1.0"
3
+ end
@@ -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 'toy_scaffold/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "toy_scaffold"
8
+ spec.version = ToyScaffold::VERSION
9
+ spec.authors = ["lulalala"]
10
+ spec.email = ["mark@goodlife.tw"]
11
+
12
+ spec.summary = %q{Scaffold for Rails beginners}
13
+ spec.description = %q{Scaffold for Rails beginners. Being explicit is favored over DRY principle.}
14
+ spec.homepage = "https://github.com/lulalala/toy_scaffold"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.8"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+
24
+ spec.add_dependency "railties", "> 4.0"
25
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: toy_scaffold
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - lulalala
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-03-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.8'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: railties
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">"
46
+ - !ruby/object:Gem::Version
47
+ version: '4.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">"
53
+ - !ruby/object:Gem::Version
54
+ version: '4.0'
55
+ description: Scaffold for Rails beginners. Being explicit is favored over DRY principle.
56
+ email:
57
+ - mark@goodlife.tw
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - bin/console
68
+ - bin/setup
69
+ - lib/templates/rails/scaffold_controller/controller.rb
70
+ - lib/toy_scaffold.rb
71
+ - lib/toy_scaffold/version.rb
72
+ - toy_scaffold.gemspec
73
+ homepage: https://github.com/lulalala/toy_scaffold
74
+ licenses: []
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.4.5
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Scaffold for Rails beginners
96
+ test_files: []