view_generator 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +35 -0
- data/Rakefile +1 -0
- data/lib/generators/view/USAGE +10 -0
- data/lib/generators/view/view_generator.rb +41 -0
- data/lib/view_generator/version.rb +3 -0
- data/view_generator.gemspec +19 -0
- metadata +54 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Viktor Fonic
|
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,35 @@
|
|
1
|
+
# ViewGenerator
|
2
|
+
|
3
|
+
Generates views for existing ActiveRecord model passed as argument.
|
4
|
+
No need to specify model attributes, it will pick them up from attr_accessible
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'view_generator'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install view_generator
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
Example:
|
23
|
+
|
24
|
+
rails generate view Thing
|
25
|
+
|
26
|
+
This will create:
|
27
|
+
* 4 CRUD views for Thing model, based on Thing accessible attributes and on default template engine
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
1. Fork it
|
32
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
33
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
34
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
35
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module View
|
2
|
+
class ViewGenerator < Rails::Generators::NamedBase
|
3
|
+
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
|
4
|
+
|
5
|
+
def self.start(args, config)
|
6
|
+
begin
|
7
|
+
modelClass = eval(args[0].camelize)
|
8
|
+
|
9
|
+
accessible_attributes = modelClass.accessible_attributes.to_a
|
10
|
+
accessible_attributes.delete_if(&:empty?)
|
11
|
+
accessible_attributes = modelClass.new.attributes.keys - modelClass.protected_attributes.to_a if accessible_attributes.blank?
|
12
|
+
accessible_attributes.each do |attribute|
|
13
|
+
if attribute != "created_at" && attribute != "updated_at"
|
14
|
+
attributes_string = attribute.to_s + ":" + modelClass.columns_hash[attribute].type.to_s # + " "
|
15
|
+
args << attributes_string
|
16
|
+
end
|
17
|
+
end
|
18
|
+
rescue
|
19
|
+
ensure
|
20
|
+
super
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def check_if_model_exists
|
25
|
+
begin
|
26
|
+
modelClass = eval(name.camelize)
|
27
|
+
raise if modelClass.table_exists? == false
|
28
|
+
rescue NameError
|
29
|
+
puts "No such model: " + name.camelize
|
30
|
+
puts "Try writing your model name in singular"
|
31
|
+
raise $!
|
32
|
+
rescue
|
33
|
+
puts "Table " + name + " doesn't exist."
|
34
|
+
puts "Try running 'rake db:migrate'"
|
35
|
+
raise $!
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
hook_for :template_engine, :as => :scaffold
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'view_generator/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "view_generator"
|
8
|
+
gem.version = ViewGenerator::VERSION
|
9
|
+
gem.author = "Viktor Fonic"
|
10
|
+
gem.email = ["viktor.fonic@gmail.com"]
|
11
|
+
gem.description = %q{Generator of views for existing models}
|
12
|
+
gem.summary = %q{Generates views for existing model passed as argument}
|
13
|
+
gem.homepage = ""
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: view_generator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Viktor Fonic
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-04-23 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Generator of views for existing models
|
15
|
+
email:
|
16
|
+
- viktor.fonic@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- Gemfile
|
23
|
+
- LICENSE.txt
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- lib/generators/view/USAGE
|
27
|
+
- lib/generators/view/view_generator.rb
|
28
|
+
- lib/view_generator/version.rb
|
29
|
+
- view_generator.gemspec
|
30
|
+
homepage: ''
|
31
|
+
licenses: []
|
32
|
+
post_install_message:
|
33
|
+
rdoc_options: []
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ! '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
requirements: []
|
49
|
+
rubyforge_project:
|
50
|
+
rubygems_version: 1.8.25
|
51
|
+
signing_key:
|
52
|
+
specification_version: 3
|
53
|
+
summary: Generates views for existing model passed as argument
|
54
|
+
test_files: []
|