bridgescaffold 1.0.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: 6c07bb4df7a9e31db78474643ef710d6d095eac1
4
+ data.tar.gz: 66c8162ba5359d49af555d2d30f9060c628c368c
5
+ SHA512:
6
+ metadata.gz: 858744af43445643d3d76f476166f4f695933e3dc56a1d228d5b7bd6bf962f13beec1bc10d91acfb675a879abf3a6378b83f2a2f8a121581fa973933c813879a
7
+ data.tar.gz: f39962330e7654e13505a9e83202f721edb1f36441d117e47f9984dbbc539575c3f7867b55158a2f6dcf059a417dca93a829ce41254f0112940f27d571edd682
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bridgescaffold.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Whien
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,29 @@
1
+ # Bridgescaffold
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'bridgescaffold'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install bridgescaffold
18
+
19
+ ## Usage
20
+
21
+ $ bridgescaffold project_name
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( https://github.com/[my-github-username]/bridgescaffold/fork )
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 a new Pull Request
@@ -0,0 +1,2 @@
1
+ require 'rspec/core/rake_task'
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,3 @@
1
+ gem uninstall bridgescaffold
2
+ gem build bridgescaffold.gemspec
3
+ gem install bridgescaffold
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path(File.join('..', 'lib', 'bridgescaffold', 'generators', 'app_generator'), File.dirname(__FILE__))
3
+ require File.expand_path(File.join('..', 'lib', 'bridgescaffold', 'actions'), File.dirname(__FILE__))
4
+ require File.expand_path(File.join('..', 'lib', 'bridgescaffold', 'layout_actions'), File.dirname(__FILE__))
5
+ require File.expand_path(File.join('..', 'lib', 'bridgescaffold', 'app_builder'), File.dirname(__FILE__))
6
+
7
+ templates_root = File.expand_path(File.join("..", "templates"), File.dirname(__FILE__))
8
+
9
+ Bridgescaffold::AppGenerator.source_root templates_root
10
+ Bridgescaffold::AppGenerator.source_paths << Rails::Generators::AppGenerator.source_root << templates_root
11
+ Bridgescaffold::AppGenerator.start
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bridgescaffold/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bridgescaffold"
8
+ spec.version = Bridgescaffold::VERSION
9
+ spec.authors = ["Whien"]
10
+ spec.email = ["sal95610@gmail.com"]
11
+ spec.summary = "bridgescaffold summary"
12
+ spec.description = "bridgescaffold description"
13
+ spec.homepage = "https://github.com/madeinfree/bridgescaffold.git"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
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_development_dependency 'rails', '~> 4.0.0'
22
+ spec.add_development_dependency "bundler", "~> 1.6"
23
+ end
@@ -0,0 +1,5 @@
1
+ require "bridgescaffold/version"
2
+
3
+ module Bridgescaffold
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,18 @@
1
+ module Bridgescaffold
2
+ module Actions
3
+
4
+ def replace_in_file(relative_path, find, replace)
5
+ path = File.join(destination_root, relative_path)
6
+ contents = IO.read(path)
7
+ unless contents.gsub!(find, replace)
8
+ raise "#{find.inspect} not found in #{relative_path}"
9
+ end
10
+ File.open(path, "w") { |file| file.write(contents) }
11
+ end
12
+
13
+ def add_def_in_file(relative_path, def_method)
14
+ replace_in_file(relative_path, /end\s*private/, def_method)
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,21 @@
1
+ module Bridgescaffold
2
+ class AppBuilder < Rails::AppBuilder
3
+
4
+ include Bridgescaffold::Actions
5
+ include Bridgescaffold::LayoutActions
6
+
7
+ def remove_routes_comment_and_add_scaffol_route
8
+ replace_in_file 'config/routes.rb', /Rails\.application\.routes\.draw do.*end/m, "Rails.application.routes.draw do\nend"
9
+ route "root 'topics#index'\nresources :topics do\nmember do\npost 'upvote'\nend\nend"
10
+ end
11
+
12
+ def add_controller_def_in_topics_file
13
+ add_def_in_file 'app/controllers/topics_controller.rb', "end\ndef upvote\n@topic = Topic.find(params[:id])\n@topic.votes.create\nredirect_to(topics_path)\nend\nprivate"
14
+ end
15
+
16
+ def add_template_file
17
+ template 'change_index_for_default_file.html.erb.erb', 'app/views/topics/index.html.erb', :force => true
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,75 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/rails/app/app_generator'
3
+
4
+ module Bridgescaffold
5
+ class AppGenerator < Rails::Generators::AppGenerator
6
+
7
+ def finish_template
8
+ super
9
+ end
10
+
11
+ def setup_scaffold
12
+ build :generate_scaffold
13
+ invoke :change_scaffold_default_route
14
+ end
15
+
16
+ def change_scaffold_default_route
17
+ invoke :remove_routes_comment_and_add_scaffol_route
18
+ end
19
+
20
+
21
+ def setup_migrate
22
+ build :database_migrate
23
+ end
24
+
25
+ def remove_routes_comment_and_add_scaffol_route
26
+ build :remove_routes_comment_and_add_scaffol_route
27
+ end
28
+
29
+ def setup_votes
30
+ build :generator_vote_model
31
+ end
32
+
33
+ def add_topic_vote_association
34
+ build :add_topic_association
35
+ build :add_vote_association
36
+ end
37
+
38
+ def add_controller_def_in_topics_file
39
+ build :add_controller_def_in_topics_file
40
+ end
41
+
42
+ def add_template_file
43
+ build :add_template_file
44
+ end
45
+
46
+ def change_controller_topic_create_update_path
47
+ build :change_controller_topic_create_update_path
48
+ end
49
+
50
+ def add_flash_in_index
51
+ build :add_flash_in_index
52
+ end
53
+
54
+ def remove_somthing_description
55
+ build :remove_somthing_description
56
+ end
57
+
58
+ def change_topic_title_to_link
59
+ build :change_topic_title_to_link
60
+ end
61
+
62
+ def remove_topic_index_show_edit_link
63
+ build :remove_topic_index_show_edit_link
64
+ end
65
+
66
+ def change_topic_index_destroy_to_delete
67
+ build :change_topic_index_destroy_to_delete
68
+ end
69
+
70
+ def get_builder_class
71
+ Bridgescaffold::AppBuilder
72
+ end
73
+
74
+ end
75
+ end
@@ -0,0 +1,53 @@
1
+ module Bridgescaffold
2
+ module LayoutActions
3
+
4
+ def generate_scaffold
5
+ generate 'scaffold topic title:string description:text'
6
+ end
7
+
8
+ def database_migrate
9
+ run 'rake db:migrate'
10
+ end
11
+
12
+ def generator_vote_model
13
+ generate 'model vote topic_id:integer'
14
+ build :database_migrate
15
+ end
16
+
17
+ def add_topic_association
18
+ replace_in_file 'app/models/topic.rb', /class Topic < ActiveRecord::Base\nend/, "class Topic < ActiveRecord::Base\nhas_many :votes, dependent: :destroy\nend"
19
+ end
20
+
21
+ def add_vote_association
22
+ replace_in_file 'app/models/vote.rb', /class Vote < ActiveRecord::Base\nend/, "class Vote < ActiveRecord::Base\nbelongs_to :topic\nend"
23
+ end
24
+
25
+ def change_controller_topic_create_update_path
26
+ replace_in_file 'app/controllers/topics_controller.rb', /format.html { redirect_to @topic, notice: 'Topic was successfully created.' }/, "format.html { redirect_to topics_path, notice: 'Topic was successfully created.' }"
27
+ replace_in_file 'app/controllers/topics_controller.rb', /format.html { redirect_to @topic, notice: 'Topic was successfully updated.' }/, "format.html { redirect_to topics_path, notice: 'Topic was successfully updated.' }"
28
+ end
29
+
30
+ def add_flash_in_index
31
+ replace_in_file 'app/views/layouts/application.html.erb', /<body>\s/, "<body>\n<% flash.each do |name, msg| %>\n<div><%= msg %></div>\n<% end %>"
32
+ end
33
+
34
+ def remove_somthing_description
35
+ replace_in_file 'app/views/topics/index.html.erb', /<td><%= topic.description %><\/td>/, ""
36
+ replace_in_file 'app/views/topics/index.html.erb', /<th>Description<\/th>/, ""
37
+ end
38
+
39
+ def change_topic_title_to_link
40
+ replace_in_file 'app/views/topics/index.html.erb', /<td><%= topic.title %><\/td>/, "<td><%= link_to topic.title, topic %></td>"
41
+ end
42
+
43
+ def remove_topic_index_show_edit_link
44
+ replace_in_file 'app/views/topics/index.html.erb', /<td><%= link_to 'Show', topic %><\/td>/, ""
45
+ replace_in_file 'app/views/topics/index.html.erb', /<td><%= link_to 'Edit', edit_topic_path\(topic\) %><\/td>/, ""
46
+ end
47
+
48
+ def change_topic_index_destroy_to_delete
49
+ replace_in_file 'app/views/topics/index.html.erb', /Destroy/, "delete"
50
+ end
51
+
52
+ end
53
+ end
@@ -0,0 +1,3 @@
1
+ module Bridgescaffold
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe Bridgescaffold do
4
+ it 'does stuff' do
5
+ pending # no code yet
6
+ end
7
+ end
@@ -0,0 +1,2 @@
1
+ require 'pry'
2
+ require 'bridgescaffold'
@@ -0,0 +1,29 @@
1
+ <h1>Listing topics</h1>
2
+
3
+ <table>
4
+ <thead>
5
+ <tr>
6
+ <th>Title</th>
7
+ <th>Description</th>
8
+ <th colspan="3"></th>
9
+ </tr>
10
+ </thead>
11
+
12
+ <tbody>
13
+ <%% @topics.each do |topic| %>
14
+ <tr>
15
+ <td><%%= topic.title %></td>
16
+ <td><%%= topic.description %></td>
17
+ <td><%%= pluralize(topic.votes.count, "vote") %></td>
18
+ <td><%%= button_to '+1', upvote_topic_path(topic), method: :post %></td>
19
+ <td><%%= link_to 'Show', topic %></td>
20
+ <td><%%= link_to 'Edit', edit_topic_path(topic) %></td>
21
+ <td><%%= link_to 'Destroy', topic, method: :delete, data: { confirm: 'Are you sure?' } %></td>
22
+ </tr>
23
+ <%% end %>
24
+ </tbody>
25
+ </table>
26
+
27
+ <br>
28
+
29
+ <%%= link_to 'New Topic', new_topic_path %>
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bridgescaffold
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Whien
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-12 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.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ description: bridgescaffold description
28
+ email:
29
+ - sal95610@gmail.com
30
+ executables:
31
+ - bridgescaffold
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - ".gitignore"
36
+ - Gemfile
37
+ - LICENSE.txt
38
+ - README.md
39
+ - Rakefile
40
+ - auto-build-gem.sh
41
+ - bin/bridgescaffold
42
+ - bridgescaffold.gemspec
43
+ - lib/bridgescaffold.rb
44
+ - lib/bridgescaffold/actions.rb
45
+ - lib/bridgescaffold/app_builder.rb
46
+ - lib/bridgescaffold/generators/app_generator.rb
47
+ - lib/bridgescaffold/layout_actions.rb
48
+ - lib/bridgescaffold/version.rb
49
+ - spec/bridgescaffold_spec.rb
50
+ - spec/spec_helper.rb
51
+ - templates/change_index_for_default_file.html.erb.erb
52
+ homepage: https://github.com/madeinfree/bridgescaffold.git
53
+ licenses:
54
+ - MIT
55
+ metadata: {}
56
+ post_install_message:
57
+ rdoc_options: []
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ requirements: []
71
+ rubyforge_project:
72
+ rubygems_version: 2.3.0
73
+ signing_key:
74
+ specification_version: 4
75
+ summary: bridgescaffold summary
76
+ test_files:
77
+ - spec/bridgescaffold_spec.rb
78
+ - spec/spec_helper.rb