codeigniter-scaffold 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "rubyzip"
4
+
5
+ group :development do
6
+ gem "linecache19", :git => 'git://github.com/mark-moseley/linecache'
7
+ gem "ruby-debug-base19x", "~> 0.11.30.pre4"
8
+ gem "ruby-debug19"
9
+ gem "shoulda", ">= 0"
10
+ gem "rdoc", "~> 3.12"
11
+ gem "bundler", "~> 1.1.4"
12
+ gem "jeweler", "~> 1.8.4"
13
+ gem "simplecov"
14
+ gem "rspec"
15
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,77 @@
1
+ GIT
2
+ remote: git://github.com/mark-moseley/linecache
3
+ revision: 869c6a65155068415925067e480741bd0a71527e
4
+ specs:
5
+ linecache19 (0.5.12)
6
+ ruby_core_source (>= 0.1.4)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ activesupport (3.2.7)
12
+ i18n (~> 0.6)
13
+ multi_json (~> 1.0)
14
+ archive-tar-minitar (0.5.2)
15
+ columnize (0.3.6)
16
+ diff-lcs (1.1.3)
17
+ git (1.2.5)
18
+ i18n (0.6.0)
19
+ jeweler (1.8.4)
20
+ bundler (~> 1.0)
21
+ git (>= 1.2.5)
22
+ rake
23
+ rdoc
24
+ json (1.7.4)
25
+ multi_json (1.3.6)
26
+ rake (0.9.2.2)
27
+ rdoc (3.12)
28
+ json (~> 1.4)
29
+ rspec (2.11.0)
30
+ rspec-core (~> 2.11.0)
31
+ rspec-expectations (~> 2.11.0)
32
+ rspec-mocks (~> 2.11.0)
33
+ rspec-core (2.11.1)
34
+ rspec-expectations (2.11.2)
35
+ diff-lcs (~> 1.1.3)
36
+ rspec-mocks (2.11.1)
37
+ ruby-debug-base19 (0.11.25)
38
+ columnize (>= 0.3.1)
39
+ linecache19 (>= 0.5.11)
40
+ ruby_core_source (>= 0.1.4)
41
+ ruby-debug-base19x (0.11.30.pre10)
42
+ columnize (>= 0.3.1)
43
+ linecache19 (>= 0.5.11)
44
+ rake (>= 0.8.1)
45
+ ruby_core_source (>= 0.1.4)
46
+ ruby-debug19 (0.11.6)
47
+ columnize (>= 0.3.1)
48
+ linecache19 (>= 0.5.11)
49
+ ruby-debug-base19 (>= 0.11.19)
50
+ ruby_core_source (0.1.5)
51
+ archive-tar-minitar (>= 0.5.2)
52
+ rubyzip (0.9.9)
53
+ shoulda (3.1.1)
54
+ shoulda-context (~> 1.0)
55
+ shoulda-matchers (~> 1.2)
56
+ shoulda-context (1.0.0)
57
+ shoulda-matchers (1.2.0)
58
+ activesupport (>= 3.0.0)
59
+ simplecov (0.6.4)
60
+ multi_json (~> 1.0)
61
+ simplecov-html (~> 0.5.3)
62
+ simplecov-html (0.5.3)
63
+
64
+ PLATFORMS
65
+ ruby
66
+
67
+ DEPENDENCIES
68
+ bundler (~> 1.1.4)
69
+ jeweler (~> 1.8.4)
70
+ linecache19!
71
+ rdoc (~> 3.12)
72
+ rspec
73
+ ruby-debug-base19x (~> 0.11.30.pre4)
74
+ ruby-debug19
75
+ rubyzip
76
+ shoulda
77
+ simplecov
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 jribeiro
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 ADDED
@@ -0,0 +1,26 @@
1
+ = codeigniter-scaffold
2
+
3
+ Simple scaffold generator for codeigniter 2.1.
4
+
5
+ == Usage
6
+
7
+ codeigniter-scaffold [options...]
8
+ -h, --help show this help
9
+ -i, --init unzip a codeigniter 2.1.2 installaion in the current dir
10
+ -s, --scaffold <model-name> field1:string, field2:text field3:integer, and so on..
11
+
12
+ == Contributing to codeigniter-scaffold
13
+
14
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
15
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
16
+ * Fork the project.
17
+ * Start a feature/bugfix branch.
18
+ * Commit and push until you are happy with your contribution.
19
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
20
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
21
+
22
+ == Copyright
23
+
24
+ Copyright (c) 2012 jribeiro. See LICENSE.txt for
25
+ further details.
26
+
data/README.rdoc ADDED
@@ -0,0 +1,26 @@
1
+ = codeigniter-scaffold
2
+
3
+ Simple scaffold generator for codeigniter 2.1.
4
+
5
+ == Usage
6
+
7
+ codeigniter-scaffold [options...]
8
+ -h, --help show this help
9
+ -i, --init unzip a codeigniter 2.1.2 installaion in the current dir
10
+ -s, --scaffold <model-name> field1:string, field2:text field3:integer, and so on..
11
+
12
+ == Contributing to codeigniter-scaffold
13
+
14
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
15
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
16
+ * Fork the project.
17
+ * Start a feature/bugfix branch.
18
+ * Commit and push until you are happy with your contribution.
19
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
20
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
21
+
22
+ == Copyright
23
+
24
+ Copyright (c) 2012 jribeiro. See LICENSE.txt for
25
+ further details.
26
+
data/Rakefile ADDED
@@ -0,0 +1,44 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ gem.name = "codeigniter-scaffold"
17
+ gem.homepage = "http://github.com/zekitow/codeigniter-scaffold"
18
+ gem.license = "MIT"
19
+ gem.summary = "Simple gem for generate scaffolds for codeigniter"
20
+ gem.description = %Q{TODO: longer description of your gem}
21
+ gem.email = "zekitow@gmail.com"
22
+ gem.authors = ["jribeiro"]
23
+ # dependencies defined in Gemfile
24
+ end
25
+ Jeweler::RubygemsDotOrgTasks.new
26
+
27
+ require 'rake/testtask'
28
+ Rake::TestTask.new(:test) do |test|
29
+ test.libs << 'lib' << 'test'
30
+ test.pattern = 'test/**/test_*.rb'
31
+ test.verbose = true
32
+ end
33
+
34
+ task :default => :test
35
+
36
+ require 'rdoc/task'
37
+ Rake::RDocTask.new do |rdoc|
38
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
39
+
40
+ rdoc.rdoc_dir = 'rdoc'
41
+ rdoc.title = "codeigniter-scaffold #{version}"
42
+ rdoc.rdoc_files.include('README*')
43
+ rdoc.rdoc_files.include('lib/**/*.rb')
44
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.dirname(__FILE__) + '/../lib/codeigniter_scaffold'
4
+
5
+ begin
6
+ CodeigniterScaffold::Executor.new.run(ARGV.dup)
7
+ end
@@ -0,0 +1,89 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "codeigniter-scaffold"
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["jribeiro"]
12
+ s.date = "2012-08-13"
13
+ s.description = "Simple codeigniter scaffolder"
14
+ s.email = "zekitow@gmail.com"
15
+ s.executables = ["codeigniter-scaffold"]
16
+ s.extra_rdoc_files = [
17
+ "LICENSE.txt",
18
+ "README",
19
+ "README.rdoc"
20
+ ]
21
+ s.files = [
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README",
26
+ "README.rdoc",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "bin/codeigniter-scaffold",
30
+ "codeigniter-scaffold.gemspec",
31
+ "lib/codeigniter_scaffold.rb",
32
+ "lib/codeigniter_scaffold/attribute.rb",
33
+ "lib/codeigniter_scaffold/command/help.rb",
34
+ "lib/codeigniter_scaffold/command/init.rb",
35
+ "lib/codeigniter_scaffold/command/scaffold.rb",
36
+ "lib/codeigniter_scaffold/executor.rb",
37
+ "lib/resources/ci_2.1.2.zip",
38
+ "lib/resources/controller.php",
39
+ "lib/resources/migration.sql",
40
+ "lib/resources/model.php",
41
+ "lib/resources/view_create.php",
42
+ "lib/resources/view_index.php",
43
+ ]
44
+ s.homepage = "http://github.com/zekitow/codeigniter-scaffold"
45
+ s.licenses = ["MIT"]
46
+ s.require_paths = ["lib"]
47
+ s.rubygems_version = "1.8.24"
48
+ s.summary = "Simple gem for generate scaffolds for codeigniter"
49
+
50
+ if s.respond_to? :specification_version then
51
+ s.specification_version = 3
52
+
53
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
54
+ s.add_runtime_dependency(%q<rubyzip>, [">= 0"])
55
+ s.add_development_dependency(%q<linecache19>, [">= 0"])
56
+ s.add_development_dependency(%q<ruby-debug-base19x>, ["~> 0.11.30.pre4"])
57
+ s.add_development_dependency(%q<ruby-debug19>, [">= 0"])
58
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
59
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
60
+ s.add_development_dependency(%q<bundler>, ["~> 1.1.4"])
61
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
62
+ s.add_development_dependency(%q<simplecov>, [">= 0"])
63
+ s.add_development_dependency(%q<rspec>, [">= 0"])
64
+ else
65
+ s.add_dependency(%q<rubyzip>, [">= 0"])
66
+ s.add_dependency(%q<linecache19>, [">= 0"])
67
+ s.add_dependency(%q<ruby-debug-base19x>, ["~> 0.11.30.pre4"])
68
+ s.add_dependency(%q<ruby-debug19>, [">= 0"])
69
+ s.add_dependency(%q<shoulda>, [">= 0"])
70
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
71
+ s.add_dependency(%q<bundler>, ["~> 1.1.4"])
72
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
73
+ s.add_dependency(%q<simplecov>, [">= 0"])
74
+ s.add_dependency(%q<rspec>, [">= 0"])
75
+ end
76
+ else
77
+ s.add_dependency(%q<rubyzip>, [">= 0"])
78
+ s.add_dependency(%q<linecache19>, [">= 0"])
79
+ s.add_dependency(%q<ruby-debug-base19x>, ["~> 0.11.30.pre4"])
80
+ s.add_dependency(%q<ruby-debug19>, [">= 0"])
81
+ s.add_dependency(%q<shoulda>, [">= 0"])
82
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
83
+ s.add_dependency(%q<bundler>, ["~> 1.1.4"])
84
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
85
+ s.add_dependency(%q<simplecov>, [">= 0"])
86
+ s.add_dependency(%q<rspec>, [">= 0"])
87
+ end
88
+ end
89
+
@@ -0,0 +1,14 @@
1
+ module CodeigniterScaffold
2
+ end
3
+
4
+ require 'rubygems'
5
+ require 'erb'
6
+ require 'zip/zipfilesystem'
7
+
8
+ require 'codeigniter_scaffold/command/init'
9
+ require 'codeigniter_scaffold/command/scaffold'
10
+ require 'codeigniter_scaffold/command/help'
11
+ require 'codeigniter_scaffold/executor'
12
+ require 'codeigniter_scaffold/attribute'
13
+
14
+ #require 'ruby-debug'
@@ -0,0 +1,31 @@
1
+ module CodeigniterScaffold
2
+ class Attribute
3
+
4
+ attr_accessor :name, :type, :mysql_type
5
+
6
+ def initialize(argument)
7
+ @name = argument.split(":")[0].downcase
8
+ @type = argument.split(":")[1].downcase
9
+ @mysql_type = find_mysql_type
10
+ validate
11
+ end
12
+
13
+ private
14
+ def self.valid_types
15
+ %w(string text integer)
16
+ end
17
+
18
+ def validate
19
+ unless Attribute.valid_types.include?(@type)
20
+ puts "Attribute #{@type} is not supported. The supported attributes types are: #{Attribute.valid_types.join(", ")}"
21
+ Kernel.exit
22
+ end
23
+ end
24
+
25
+ def find_mysql_type
26
+ return "VARCHAR(255)" if @type == 'string'
27
+ return "INT" if @type == 'integer'
28
+ "TEXT"
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,14 @@
1
+ module CodeigniterScaffold
2
+ module Command
3
+ class Help
4
+
5
+ def run(args)
6
+ Kernel.puts("Usage: codeigniter-scaffold [options...]\r\n")
7
+ Kernel.puts(" -h, --help show this help\r\n")
8
+ Kernel.puts(" -i, --init unzip a codeigniter 2.1.2 installaion in the current dir\r\n")
9
+ Kernel.puts(" -s, --scaffold <model-name> field1:string, field2:text field3:integer, and so on.. \r\n")
10
+ end
11
+
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,22 @@
1
+ module CodeigniterScaffold
2
+ module Command
3
+ class Init
4
+
5
+ def run(args)
6
+ ci_dir = File.dirname(__FILE__) + "/../../resources/ci_2.1.2.zip"
7
+ unzip_file(ci_dir, Dir.pwd)
8
+ end
9
+
10
+ def unzip_file(file, destination)
11
+ ::Zip::ZipFile.open(file) do |zip_file|
12
+ zip_file.each do |f|
13
+ f_path = File.join(destination, f.name)
14
+ FileUtils.mkdir_p(File.dirname(f_path))
15
+ zip_file.extract(f, f_path) unless File.exist?(f_path)
16
+ end
17
+ end
18
+ end
19
+
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,57 @@
1
+ module CodeigniterScaffold
2
+ module Command
3
+ class Scaffold
4
+
5
+ attr_accessor :model, :attributes
6
+
7
+ def run(args)
8
+ return Kernel.puts("Some arguments are needed, please, try again.") if not valid?(args)
9
+ parse(args)
10
+
11
+ create("controller.php","application/controllers/#{@model.downcase}.php")
12
+ create("model.php","application/models/#{@model.downcase}_model.php")
13
+ create("migration.sql","application/migrations/create_#{@model.downcase}.sql")
14
+ mkdir ("application/views/#{@model.downcase}")
15
+ create("view_create.php","application/views/#{@model.downcase}/create.php")
16
+ create("view_index.php","application/views/#{@model.downcase}/index.php")
17
+ end
18
+
19
+ protected
20
+ def valid?(args)
21
+ return false if not args or args.empty?
22
+ return false if args.size <= 1
23
+ true
24
+ end
25
+
26
+ def parse(args)
27
+ @model = args.shift.capitalize
28
+ @attributes = Array.new
29
+ args.each {|a| @attributes << Attribute.new(a) }
30
+ end
31
+
32
+ private
33
+ def create(template, output)
34
+ parse_to(template, output)
35
+ puts "File #{output} was successfully created."
36
+ end
37
+
38
+ def parse_to(path_to_template, path_to_output)
39
+ resource_dir = File.dirname(__FILE__) + "/../../resources/"
40
+ @template = File.read(File.join(resource_dir, path_to_template))
41
+ template = ERB.new(@template)
42
+ file = File.new(path_to_output,"w")
43
+ file.write(template.result(binding))
44
+ file.close
45
+ end
46
+
47
+ def mkdir(directory_name)
48
+ begin
49
+ Dir::mkdir(directory_name)
50
+ rescue
51
+ # directory exists
52
+ end
53
+ end
54
+
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,19 @@
1
+ module CodeigniterScaffold
2
+ class Executor
3
+
4
+ def run(args)
5
+ action = args.shift if args
6
+ COMMANDS.fetch(action, Command::Help).new.run(args)
7
+ end
8
+ end
9
+
10
+ COMMANDS = {
11
+ "--help" => Command::Help,
12
+ "--init" => Command::Init,
13
+ "--scaffold" => Command::Scaffold,
14
+ "-h" => Command::Help,
15
+ "-i" => Command::Init,
16
+ "-s" => Command::Scaffold
17
+ }
18
+
19
+ end
Binary file
@@ -0,0 +1,66 @@
1
+ <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2
+
3
+ /**
4
+ * <%=@model.capitalize%> Controller.
5
+ */
6
+ class <%=@model.capitalize%> extends CI_Controller {
7
+
8
+ function __construct() {
9
+ parent::__construct();
10
+ $this->load->helper(array('form','file','url'));
11
+ $this->load->library('form_validation');
12
+ $this->load->model('<%=@model.downcase%>_model');
13
+ }
14
+
15
+ # GET /<%=@model.downcase%>
16
+ function index() {
17
+ $data['<%=@model.downcase%>'] = $this-><%=@model.downcase%>_model->find();
18
+ $this->load->view('/<%=@model.downcase%>/index', $data);
19
+ }
20
+
21
+ # GET /<%=@model.downcase%>/create
22
+ function create() {
23
+ $this->load->view('/<%=@model.downcase%>/create');
24
+ }
25
+
26
+ # GET /<%=@model.downcase%>/edit/1
27
+ function edit() {
28
+ $id = $this->uri->segment(3);
29
+ $data['<%=@model.downcase%>'] = $this-><%=@model.downcase%>_model->find($id);
30
+ $this->load->view('/<%=@model.downcase%>/create', $data);
31
+ }
32
+
33
+ # GET /<%=@model.downcase%>/destroy/1
34
+ function destroy() {
35
+ $id = $this->uri->segment(3);
36
+ $data['<%=@model.downcase%>'] = $this-><%=@model.downcase%>_model->destroy($id);
37
+ redirect('/<%=@model.downcase%>/index', 'refresh');
38
+ }
39
+
40
+ # POST /<%=@model.downcase%>/save
41
+ function save() {
42
+ <% @attributes.each { |f| %>
43
+ $this->form_validation->set_rules('<%= f.name %>', '<%= f.name.capitalize %>', 'required');<% } %>
44
+
45
+ if ($this->form_validation->run()) {
46
+
47
+ $data[] = array();
48
+ $data['id'] = $this->input->post('id', TRUE);<% @attributes.each { |f| %>
49
+ $data['<%= f.name %>'] = $this->input->post('<%= f.name %>', TRUE);<% } %>
50
+ $this-><%=@model.downcase%>_model->save($data);
51
+ redirect('/<%=@model.downcase%>/index', 'refresh');
52
+ }
53
+ $data['<%=@model.downcase%>'] = $this->rebuild();
54
+ $this->load->view('/<%=@model.downcase%>/create',$data);
55
+ }
56
+
57
+ function rebuild() {
58
+ $object = new <%=@model.downcase%>_model();
59
+ $object->id = $this->input->post('id', TRUE);<% @attributes.each { |f| %>
60
+ $object-><%= f.name %> = $this->input->post('<%= f.name %>', TRUE);<% } %>
61
+ return $object;
62
+ }
63
+ }
64
+
65
+ ?>
66
+
@@ -0,0 +1,7 @@
1
+ CREATE TABLE `<%=@model.downcase%>` (
2
+ `id` INT NOT NULL AUTO_INCREMENT,<% @attributes.each { |f| %>
3
+ `<%= f.name %>` <%= f.mysql_type %> DEFAULT NULL, <% } %>
4
+ `created_at` DATETIME NOT NULL,
5
+ `updated_at` DATETIME DEFAULT NULL,
6
+ PRIMARY KEY (`id`)
7
+ );
@@ -0,0 +1,43 @@
1
+ <?php
2
+
3
+ /**
4
+ * <%=@model.capitalize%> Model.
5
+ */
6
+ class <%=@model.capitalize%>_model extends CI_Model {
7
+
8
+ # save $data on '<%=@model.downcase%>'
9
+ function save($data) {
10
+ <% @attributes.each { |f| %>
11
+ $this->db->set('<%= f.name %>', $data['<%= f.name %>']);<% } %>
12
+
13
+ if($data['id'] == NULL) {
14
+ $this->db->set('created_at', date('Y-m-d h:i:s',time()));
15
+ $this->db->insert('<%=@model.downcase%>');
16
+ } else {
17
+ $this->db->where('id', $data['id']);
18
+ $this->db->set('updated_at', date('Y-m-d h:i:s',time()));
19
+ $this->db->update('<%=@model.downcase%>');
20
+ }
21
+
22
+ return $this->db->affected_rows();
23
+ }
24
+
25
+ # retrives $data from '<%=@model.downcase%>'
26
+ function find($id = NULL) {
27
+ if($id != NULL) {
28
+ $this->db->where('id', $id);
29
+ return $this->db->get('<%=@model.downcase%>')->row();
30
+ } else {
31
+ return $this->db->get('<%=@model.downcase%>')->result();
32
+ }
33
+ }
34
+
35
+ # destroy $data from '<%=@model.downcase%>'
36
+ function destroy($id) {
37
+ $this->db->where('id', $id);
38
+ $this->db->delete('<%=@model.downcase%>');
39
+
40
+ return $this->db->affected_rows();
41
+ }
42
+
43
+ }
@@ -0,0 +1,16 @@
1
+ <h1>Create</h1>
2
+ <?php echo form_open('<%=@model.downcase%>/save'); ?>
3
+ <div class="error"><?php echo validation_errors(); ?></div>
4
+ <input type="hidden" name="id" value="<?php echo isset($<%=@model.downcase%>)?$<%=@model.downcase%>->id:''?>"/>
5
+ <% @attributes.each { |f| %>
6
+ <p>
7
+ <label for="<%= f.name %>"><%= f.name %>:</label><br/><% if f.type == 'string' %>
8
+ <input type="text" name="<%= f.name %>" value="<?php echo isset($<%=@model.downcase%>)?$<%=@model.downcase%>-><%= f.name %>:''?>"/><% end %>
9
+ <% if f.type == 'text' %>
10
+ <textarea name="<%= f.name %>"><?php echo isset($<%=@model.downcase%>)?$<%=@model.downcase%>-><%= f.name %>:''?></textarea><% end %>
11
+
12
+ </p>
13
+ <% } %>
14
+ <input type="submit" value="Create"/>
15
+ </form>
16
+
@@ -0,0 +1,20 @@
1
+ <h1><%=@model.capitalize%></h1>
2
+ <table>
3
+ <tr>
4
+ <th>Id</th>
5
+ <% @attributes.each { | f | %>
6
+ <th><%= f.name %></th><% } %>
7
+ </tr>
8
+ <?php foreach ($<%=@model.downcase%> as $object) { ?>
9
+ <tr>
10
+ <td><?php echo $object->id ?></td>
11
+ <% @attributes.each { | f | %>
12
+ <td><?php echo $object-><%= f.name %> ?></td><% } %>
13
+ <td><?php echo anchor('/<%=@model.downcase%>/edit/'.$object->id, 'Edit'); ?></td>
14
+ <td><?php echo anchor('/<%=@model.downcase%>/destroy/'.$object->id, 'Destroy'); ?></td>
15
+
16
+ </tr>
17
+ <?php } ?>
18
+ </table>
19
+
20
+ <?php echo anchor('/<%=@model.downcase%>/create','Create'); ?>
metadata ADDED
@@ -0,0 +1,230 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: codeigniter-scaffold
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - jribeiro
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rubyzip
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: linecache19
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: ruby-debug-base19x
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 0.11.30.pre4
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.11.30.pre4
62
+ - !ruby/object:Gem::Dependency
63
+ name: ruby-debug19
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: shoulda
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: rdoc
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: '3.12'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: '3.12'
110
+ - !ruby/object:Gem::Dependency
111
+ name: bundler
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: 1.1.4
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ~>
124
+ - !ruby/object:Gem::Version
125
+ version: 1.1.4
126
+ - !ruby/object:Gem::Dependency
127
+ name: jeweler
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ~>
132
+ - !ruby/object:Gem::Version
133
+ version: 1.8.4
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ~>
140
+ - !ruby/object:Gem::Version
141
+ version: 1.8.4
142
+ - !ruby/object:Gem::Dependency
143
+ name: simplecov
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ - !ruby/object:Gem::Dependency
159
+ name: rspec
160
+ requirement: !ruby/object:Gem::Requirement
161
+ none: false
162
+ requirements:
163
+ - - ! '>='
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ type: :development
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ description: Simple codeigniter scaffolder
175
+ email: zekitow@gmail.com
176
+ executables:
177
+ - codeigniter-scaffold
178
+ extensions: []
179
+ extra_rdoc_files:
180
+ - LICENSE.txt
181
+ - README
182
+ - README.rdoc
183
+ files:
184
+ - Gemfile
185
+ - Gemfile.lock
186
+ - LICENSE.txt
187
+ - README
188
+ - README.rdoc
189
+ - Rakefile
190
+ - VERSION
191
+ - bin/codeigniter-scaffold
192
+ - codeigniter-scaffold.gemspec
193
+ - lib/codeigniter_scaffold.rb
194
+ - lib/codeigniter_scaffold/attribute.rb
195
+ - lib/codeigniter_scaffold/command/help.rb
196
+ - lib/codeigniter_scaffold/command/init.rb
197
+ - lib/codeigniter_scaffold/command/scaffold.rb
198
+ - lib/codeigniter_scaffold/executor.rb
199
+ - lib/resources/ci_2.1.2.zip
200
+ - lib/resources/controller.php
201
+ - lib/resources/migration.sql
202
+ - lib/resources/model.php
203
+ - lib/resources/view_create.php
204
+ - lib/resources/view_index.php
205
+ homepage: http://github.com/zekitow/codeigniter-scaffold
206
+ licenses:
207
+ - MIT
208
+ post_install_message:
209
+ rdoc_options: []
210
+ require_paths:
211
+ - lib
212
+ required_ruby_version: !ruby/object:Gem::Requirement
213
+ none: false
214
+ requirements:
215
+ - - ! '>='
216
+ - !ruby/object:Gem::Version
217
+ version: '0'
218
+ required_rubygems_version: !ruby/object:Gem::Requirement
219
+ none: false
220
+ requirements:
221
+ - - ! '>='
222
+ - !ruby/object:Gem::Version
223
+ version: '0'
224
+ requirements: []
225
+ rubyforge_project:
226
+ rubygems_version: 1.8.24
227
+ signing_key:
228
+ specification_version: 3
229
+ summary: Simple gem for generate scaffolds for codeigniter
230
+ test_files: []