codeigniter3-scaffold 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OGJhNjFlNTY3NzVkZDMxYjM1NzUxYWM0ZDlmZGE0ZGM0ZWM0ZDQwNA==
5
+ data.tar.gz: !binary |-
6
+ OTU0YWQyZjFjYmYzZWNkOWFkNjcxNTNkNGJmODE3NGEzZDFjZTVkOQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ MjFmMWRhOWZhMGZkZTYzZTNjNDZhZmNhZTQxNGE0M2U4NDkyOGQ3YmU5MmJi
10
+ ZTAwNDA5MzhkYjk0YjE0MzYwZmFhMDQ1ZWNkNDVmMzU4NWEzOTdlMDc0ZTg2
11
+ MzM1MjRlNTgwNzUzODYyYTgzODNmNGRhMmIwZWFmNzE4NjM5YzA=
12
+ data.tar.gz: !binary |-
13
+ ODE5ZTdmNzZlMGM2OWRmNjk5ZDczNWViODE1NDBjNjMxMDg4MmJkNmQwOTQ3
14
+ ZjUwMDAyMDNlNjMzYTcxMjcyYzM0NWRjM2UxYjIzYmEzYjZkNTgwYzY1OWQ0
15
+ YjRhNTcwMDkzNGY4NzJmMDY1MzZhOTNlYjdkODdhMzJhNTRmZDU=
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ script: bundle exec rspec spec
5
+ before_install:
6
+ - "echo 'gem: --no-ri --no-rdoc' > ~/.gemrc"
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) 2016 universidadecodeigniter
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,36 @@
1
+ # CodeIgniter 3 Scaffold
2
+
3
+ Simple scaffold generator for CodeIgniter 3.1.0 now using Twitter Bootstrap templates!
4
+
5
+ ## Instalation
6
+
7
+ This scaffold is a gem of Ruby, then you need to have Ruby installed on your machine.
8
+
9
+ See the following command sequence to install this gem:
10
+
11
+ ```
12
+ gem install rubyzip
13
+ gem install codeigniter3-scaffold
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ codeigniter3-scaffold [options...]
19
+ -h, --help show this help
20
+ -i, --init unzip a codeigniter 3.1.0 installation in the current dir
21
+ -s, --scaffold <model-name> field1:string field2:text field3:integer, and so on..
22
+
23
+ ## Pre-setup
24
+
25
+ * After running 'codeigniter3-scaffold --init':
26
+ * Open 'application/config/config.php' and set-up the 'base_url' property;
27
+ * Open 'application/config/database.php' and set-up your database settings;
28
+
29
+ * After running 'codeigniter3-scaffold --scaffold [options...]'
30
+ * Go to 'application/migrations' and run the generated script into your database;
31
+
32
+ * Have fun =)
33
+
34
+ ## Copyright
35
+
36
+ Copyright (c) 2016 Universidade CodeIgniter & JLamim.
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # CodeIgniter 3 Scaffold
2
+
3
+ Simple scaffold generator for CodeIgniter 3.1.0 now using Twitter Bootstrap templates!
4
+
5
+ ## Instalation
6
+
7
+ This scaffold is a gem of Ruby, then you need to have Ruby installed on your machine.
8
+
9
+ See the following command sequence to install this gem:
10
+
11
+ ```
12
+ gem install rubyzip
13
+ gem install codeigniter3-scaffold
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ codeigniter3-scaffold [options...]
19
+ -h, --help show this help
20
+ -i, --init unzip a CodeIgniter 3.1.0 installation in the current dir
21
+ -s, --scaffold <model-name> field1:string field2:text field3:integer, and so on..
22
+
23
+ ## Pre-setup
24
+
25
+ * After running 'codeigniter3-scaffold --init':
26
+ * Open 'application/config/config.php' and set-up the 'base_url' property;
27
+ * Open 'application/config/database.php' and set-up your database settings;
28
+
29
+ * After running 'codeigniter3-scaffold --scaffold [options...]'
30
+ * Go to 'application/migrations' and run the generated script into your database;
31
+
32
+ * Have fun =)
33
+
34
+ ## Copyright
35
+
36
+ Copyright (c) 2016 Universidade CodeIgniter & JLamim.
data/Rakefile ADDED
@@ -0,0 +1,45 @@
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 = "codeigniter3-scaffold"
17
+ gem.homepage = "http://github.com/universidadecodeigniter/codeigniter-scaffold"
18
+ gem.license = "MIT"
19
+ gem.summary = "Simple gem for generate scaffolds for codeigniter 3"
20
+ gem.description = "Simple scaffold generator for codeigniter 3.1.0 now using Twitter Bootstrap templates!"
21
+ gem.email = "contato@universidadecodeigniter.com.br"
22
+ gem.authors = ["jlamim","universidadecodeigniter"]
23
+ gem.executables = ["codeigniter3-scaffold"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ task :default => :test
36
+
37
+ require 'rdoc/task'
38
+ Rake::RDocTask.new do |rdoc|
39
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
40
+
41
+ rdoc.rdoc_dir = 'rdoc'
42
+ rdoc.title = "codeigniter3-scaffold #{version}"
43
+ rdoc.rdoc_files.include('README*')
44
+ rdoc.rdoc_files.include('lib/**/*.rb')
45
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.1.0
@@ -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,96 @@
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
+ # stub: codeigniter3-scaffold 1.1.0 ruby lib
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "codeigniter3-scaffold"
9
+ s.version = "1.1.0"
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib"]
13
+ s.authors = ["jlamim", "universidadecodeigniter"]
14
+ s.date = "2016-09-10"
15
+ s.description = "Simple scaffold generator for codeigniter 3.1.0 now using Twitter Bootstrap templates!"
16
+ s.email = "contato@universidadecodeigniter.com.br"
17
+ s.executables = ["codeigniter3-scaffold"]
18
+ s.extra_rdoc_files = [
19
+ "LICENSE.txt",
20
+ "README",
21
+ "README.md"
22
+ ]
23
+ s.files = [
24
+ ".travis.yml",
25
+ "Gemfile",
26
+ "Gemfile.lock",
27
+ "LICENSE.txt",
28
+ "README",
29
+ "README.md",
30
+ "Rakefile",
31
+ "VERSION",
32
+ "bin/codeigniter3-scaffold",
33
+ "codeigniter3-scaffold.gemspec",
34
+ "lib/codeigniter_scaffold.rb",
35
+ "lib/codeigniter_scaffold/attribute.rb",
36
+ "lib/codeigniter_scaffold/command/help.rb",
37
+ "lib/codeigniter_scaffold/command/init.rb",
38
+ "lib/codeigniter_scaffold/command/scaffold.rb",
39
+ "lib/codeigniter_scaffold/executor.rb",
40
+ "lib/resources/ci_3.1.0.zip",
41
+ "lib/resources/controller.php",
42
+ "lib/resources/migration.sql",
43
+ "lib/resources/model.php",
44
+ "lib/resources/view_create.php",
45
+ "lib/resources/view_index.php",
46
+ "spec/codeigniter_scaffold/command/help_spec.rb",
47
+ "spec/codeigniter_scaffold/command/init_spec.rb",
48
+ "spec/codeigniter_scaffold/command/scaffold_spec.rb",
49
+ "spec/codeigniter_scaffold/executor_spec.rb",
50
+ "spec/spec_helper.rb"
51
+ ]
52
+ s.homepage = "http://github.com/universidadecodeigniter/codeigniter-scaffold"
53
+ s.licenses = ["MIT"]
54
+ s.rubygems_version = "2.4.8"
55
+ s.summary = "Simple gem for generate scaffolds for codeigniter 3"
56
+
57
+ if s.respond_to? :specification_version then
58
+ s.specification_version = 4
59
+
60
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
61
+ s.add_runtime_dependency(%q<rubyzip>, [">= 0"])
62
+ s.add_development_dependency(%q<linecache19>, [">= 0"])
63
+ s.add_development_dependency(%q<ruby-debug-base19x>, ["~> 0.11.30.pre4"])
64
+ s.add_development_dependency(%q<ruby-debug19>, [">= 0"])
65
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
66
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
67
+ s.add_development_dependency(%q<bundler>, ["~> 1.1.4"])
68
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
69
+ s.add_development_dependency(%q<simplecov>, [">= 0"])
70
+ s.add_development_dependency(%q<rspec>, [">= 0"])
71
+ else
72
+ s.add_dependency(%q<rubyzip>, [">= 0"])
73
+ s.add_dependency(%q<linecache19>, [">= 0"])
74
+ s.add_dependency(%q<ruby-debug-base19x>, ["~> 0.11.30.pre4"])
75
+ s.add_dependency(%q<ruby-debug19>, [">= 0"])
76
+ s.add_dependency(%q<shoulda>, [">= 0"])
77
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
78
+ s.add_dependency(%q<bundler>, ["~> 1.1.4"])
79
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
80
+ s.add_dependency(%q<simplecov>, [">= 0"])
81
+ s.add_dependency(%q<rspec>, [">= 0"])
82
+ end
83
+ else
84
+ s.add_dependency(%q<rubyzip>, [">= 0"])
85
+ s.add_dependency(%q<linecache19>, [">= 0"])
86
+ s.add_dependency(%q<ruby-debug-base19x>, ["~> 0.11.30.pre4"])
87
+ s.add_dependency(%q<ruby-debug19>, [">= 0"])
88
+ s.add_dependency(%q<shoulda>, [">= 0"])
89
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
90
+ s.add_dependency(%q<bundler>, ["~> 1.1.4"])
91
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
92
+ s.add_dependency(%q<simplecov>, [">= 0"])
93
+ s.add_dependency(%q<rspec>, [">= 0"])
94
+ end
95
+ end
96
+
@@ -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: codeigniter3-scaffold [options...]\r\n")
7
+ Kernel.puts(" -h, --help show this help\r\n")
8
+ Kernel.puts(" -i, --init unzip a CodeIgniter 3.1.0 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,23 @@
1
+ module CodeigniterScaffold
2
+ module Command
3
+ class Init
4
+
5
+ def run(args)
6
+ resources_dir = File.expand_path('../../resources', File.dirname(__FILE__))
7
+ ci_dir = resources_dir + "/ci_3.1.0.zip"
8
+ unzip_file(ci_dir, Dir.pwd)
9
+ end
10
+
11
+ def unzip_file(file, destination)
12
+ Zip::ZipFile.open(file) do |zip_file|
13
+ zip_file.each do |f|
14
+ f_path = File.join(destination, f.name)
15
+ FileUtils.mkdir_p(File.dirname(f_path))
16
+ zip_file.extract(f, f_path) unless File.exist?(f_path)
17
+ end
18
+ end
19
+ end
20
+
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,64 @@
1
+ module CodeigniterScaffold
2
+ module Command
3
+ class Scaffold
4
+
5
+ attr_accessor :model, :attributes
6
+
7
+ ARGS_ARE_NEEDED = "Some arguments are needed, please, try again."
8
+ ARGS_WRONG = "Something goes wrong! Aborting."
9
+
10
+ def run(args)
11
+ begin
12
+ return Kernel.puts(ARGS_ARE_NEEDED) unless valid?(args)
13
+ parse(args)
14
+
15
+ create("controller.php","application/controllers/#{@model.capitalize}.php")
16
+ create("model.php","application/models/#{@model.capitalize}_model.php")
17
+ create("migration.sql","application/migrations/create_#{@model.downcase}.sql")
18
+ mkdir ("application/views/#{@model.downcase}")
19
+ create("view_create.php","application/views/#{@model.downcase}/create.php")
20
+ create("view_index.php","application/views/#{@model.downcase}/index.php")
21
+ rescue
22
+ return Kernel.puts(ARGS_WRONG)
23
+ end
24
+ end
25
+
26
+ protected
27
+ def valid?(args)
28
+ return false if not args or args.empty?
29
+ return false if args.size <= 1
30
+ true
31
+ end
32
+
33
+ def parse(args)
34
+ @model = args.shift.capitalize
35
+ @attributes = Array.new
36
+ args.each {|a| @attributes << Attribute.new(a) }
37
+ end
38
+
39
+ private
40
+ def create(template, output)
41
+ parse_to(template, output)
42
+ puts "File #{output} was successfully created."
43
+ end
44
+
45
+ def parse_to(path_to_template, path_to_output)
46
+ resource_dir = File.dirname(__FILE__) + "/../../resources/"
47
+ @template = File.read(File.join(resource_dir, path_to_template))
48
+ template = ERB.new(@template)
49
+ file = File.new(path_to_output,"w")
50
+ file.write(template.result(binding))
51
+ file.close
52
+ end
53
+
54
+ def mkdir(directory_name)
55
+ begin
56
+ Dir::mkdir(directory_name)
57
+ rescue
58
+ # directory exists
59
+ end
60
+ end
61
+
62
+ end
63
+ end
64
+ 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,67 @@
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->model('<%=@model.capitalize%>_model');
11
+ }
12
+
13
+ # GET /<%=@model.downcase%>
14
+ function index() {
15
+ $data['<%=@model.downcase%>'] = $this-><%=@model.capitalize%>_model->find();
16
+ $data['content'] = '/<%=@model.downcase%>/index';
17
+ $this->load->view('/includes/template', $data);
18
+ }
19
+
20
+ # GET /<%=@model.downcase%>/create
21
+ function create() {
22
+ $data['content'] = '/<%=@model.downcase%>/create';
23
+ $this->load->view('/includes/template', $data);
24
+ }
25
+
26
+ # GET /<%=@model.downcase%>/edit/1
27
+ function edit() {
28
+ $id = $this->uri->segment(3);
29
+ $data['<%=@model.downcase%>'] = $this-><%=@model.capitalize%>_model->find($id);
30
+ $data['content'] = '/<%=@model.downcase%>/create';
31
+ $this->load->view('/includes/template', $data);
32
+ }
33
+
34
+ # GET /<%=@model.downcase%>/destroy/1
35
+ function destroy() {
36
+ $id = $this->uri->segment(3);
37
+ $data['<%=@model.downcase%>'] = $this-><%=@model.capitalize%>_model->destroy($id);
38
+ redirect('/<%=@model.downcase%>/index', 'refresh');
39
+ }
40
+
41
+ # POST /<%=@model.downcase%>/save
42
+ function save() {
43
+ <% @attributes.each { |f| %>
44
+ $this->form_validation->set_rules('<%= f.name %>', '<%= f.name.capitalize %>', 'required');<% } %>
45
+
46
+ if ($this->form_validation->run()) {
47
+
48
+ $data[] = array();
49
+ $data['id'] = $this->input->post('id', TRUE);<% @attributes.each { |f| %>
50
+ $data['<%= f.name %>'] = $this->input->post('<%= f.name %>', TRUE);<% } %>
51
+ $this-><%=@model.capitalize%>_model->save($data);
52
+ redirect('/<%=@model.downcase%>/index', 'refresh');
53
+ }
54
+ $data['<%=@model.downcase%>'] = $this->rebuild();
55
+ $data['content'] = '/<%=@model.downcase%>/create';
56
+ $this->load->view('/includes/template', $data);
57
+ }
58
+
59
+ function rebuild() {
60
+ $object = new <%=@model.capitalize%>_model();
61
+ $object->id = $this->input->post('id', TRUE);<% @attributes.each { |f| %>
62
+ $object-><%= f.name %> = $this->input->post('<%= f.name %>', TRUE);<% } %>
63
+ return $object;
64
+ }
65
+ }
66
+
67
+ ?>
@@ -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,15 @@
1
+ <h1>Create</h1>
2
+ <?= form_open('<%=@model.downcase%>/save','role="form"'); ?><?php if(validation_errors() != NULL && validation_errors() != '') { ?>
3
+ <div class="alert alert-danger"><?= validation_errors(); ?></div><?php } ?>
4
+ <input type="hidden" name="id" value="<?= isset($<%=@model.downcase%>)?$<%=@model.downcase%>->id:''?>"/>
5
+ <% @attributes.each { |f| %>
6
+ <div class="form-group">
7
+ <label for="<%= f.name %>"><%= f.name.capitalize %>:</label><br/><% if f.type == 'string' or f.type == 'integer' %>
8
+ <input type="text" class="form-control" name="<%= f.name %>" placeholder="Enter <%= f.name.capitalize %>" value="<?= isset($<%=@model.downcase%>)?$<%=@model.downcase%>-><%= f.name %>:''?>"/><% end %>
9
+ <% if f.type == 'text' %>
10
+ <textarea name="<%= f.name %>" class="form-control"><?= isset($<%=@model.downcase%>)?$<%=@model.downcase%>-><%= f.name %>:''?></textarea><% end %>
11
+ </div><% } %>
12
+ <input type="submit" value="Save" class="btn btn-primary"/>
13
+ <?= anchor('<%=@model.downcase%>/index','Back','class="btn btn-link"'); ?>
14
+ </form>
15
+
@@ -0,0 +1,17 @@
1
+ <h2><%=@model.capitalize%></h2>
2
+ <table class="table">
3
+ <tr>
4
+ <th>#</th><% @attributes.each { | f | %>
5
+ <th><%= f.name.capitalize %></th><% } %>
6
+ <th colspan="2"></th>
7
+ </tr>
8
+ <?php foreach ($<%=@model.downcase%> as $object) { ?>
9
+ <tr>
10
+ <td><?=$object->id ?></td><% @attributes.each { | f | %>
11
+ <td><?= $object-><%= f.name %> ?></td><% } %>
12
+ <td width="80"><?= anchor('/<%=@model.downcase%>/edit/'.$object->id, 'Edit','class="btn btn-warning"'); ?></td>
13
+ <td width="80"><?= anchor('/<%=@model.downcase%>/destroy/'.$object->id, 'Destroy','class="btn btn-danger"'); ?></td>
14
+ </tr><?php } ?>
15
+ </table>
16
+
17
+ <?= anchor('/<%=@model.downcase%>/create','Create','class="btn btn-primary"'); ?>
@@ -0,0 +1,18 @@
1
+ require "spec_helper"
2
+
3
+ describe CodeigniterScaffold::Command::Help do
4
+
5
+ context "#run" do
6
+
7
+ subject { CodeigniterScaffold::Command::Help.new.run(nil) }
8
+
9
+ it "shows the usage" do
10
+ Kernel.should_receive(:puts).with("Usage: codeigniter3-scaffold [options...]\r\n")
11
+ Kernel.should_receive(:puts).with(" -h, --help show this help\r\n")
12
+ Kernel.should_receive(:puts).with(" -i, --init unzip a CodeIgniter 3.1.0 installation in the current dir\r\n")
13
+ Kernel.should_receive(:puts).with(" -s, --scaffold <model-name> field1:string field2:text field3:integer, and so on.. \r\n")
14
+ subject
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,16 @@
1
+ require "spec_helper"
2
+
3
+ describe CodeigniterScaffold::Command::Init do
4
+
5
+ context "#run" do
6
+ before(:all) { CodeigniterScaffold::Command::Init.new.run(nil) }
7
+
8
+ after(:all) do
9
+ unziped = ["application","index.php","system"]
10
+ unziped.each { |f| FileUtils.rm_rf Dir.glob(f) }
11
+ end
12
+
13
+ it { File.should be_directory(File.join(Dir.pwd,"/application")) }
14
+ it { File.should be_directory(File.join(Dir.pwd,"/system")) }
15
+ end
16
+ end
@@ -0,0 +1,150 @@
1
+ require "spec_helper"
2
+
3
+ describe CodeigniterScaffold::Command::Scaffold do
4
+
5
+ before do
6
+ CodeigniterScaffold::Command::Init.new.run(args)
7
+ Kernel.stub(:exit)
8
+ end
9
+
10
+ after(:all) do
11
+ unziped = ["application","index.php","system"]
12
+ unziped.each { |f| FileUtils.rm_rf Dir.glob(f) }
13
+ end
14
+
15
+ let(:scaffolder) { CodeigniterScaffold::Command::Scaffold.new }
16
+
17
+ context "#run" do
18
+ let(:error_message) { "Some arguments are needed, please, try again." }
19
+ subject { CodeigniterScaffold::Command::Scaffold.new.run(args) }
20
+
21
+ context "args are not sent" do
22
+ let(:args) { [nil] }
23
+
24
+ it "show error to user" do
25
+ Kernel.should_receive(:puts).with(error_message)
26
+ subject
27
+ end
28
+ end
29
+
30
+ context "args are sent" do
31
+ context "and it's empty" do
32
+ let(:args) { "" }
33
+
34
+ it "show error to user" do
35
+ Kernel.should_receive(:puts).with(error_message)
36
+ subject
37
+ end
38
+ end
39
+
40
+ context "and it's not empty" do
41
+ context "when attributes are invalid" do
42
+ context "and it just have model name" do
43
+ let(:args) { ["user"] }
44
+
45
+ it "show error to user" do
46
+ Kernel.should_receive(:puts).with(error_message)
47
+ subject
48
+ end
49
+ end
50
+
51
+ context "with invalid attributes" do
52
+ context "and command pattern was not respected" do
53
+ let(:args) { ["user","name"] }
54
+ let(:error_message) { "Something goes wrong! Aborting." }
55
+
56
+ subject do
57
+ scaffolder.run(args)
58
+ scaffolder.attributes.first
59
+ end
60
+
61
+ it "shows generic error" do
62
+ Kernel.should_receive(:puts).with(error_message)
63
+ subject
64
+ end
65
+ end
66
+
67
+ context "and an unexpected type is sent" do
68
+ let(:args) { ["user","name:varchar2"] }
69
+
70
+ subject do
71
+ scaffolder.run(args)
72
+ scaffolder.attributes.first
73
+ end
74
+
75
+ it "validates field type" do
76
+ Kernel.should_receive(:exit)
77
+ subject
78
+ end
79
+ end
80
+
81
+ end
82
+ end
83
+
84
+ context "when attributes are valid" do
85
+ context "with model" do
86
+ let(:args) { ["user","name:string","password:string"] }
87
+
88
+ subject { CodeigniterScaffold::Command::Scaffold.new }
89
+ before { subject.run(args) }
90
+
91
+ its(:model) { should eq "User" }
92
+ end
93
+
94
+ context "with attributes" do
95
+ context "when attribute is string" do
96
+ let(:args) { ["user","name:string"] }
97
+
98
+ subject do
99
+ scaffolder.run(args)
100
+ scaffolder.attributes.first
101
+ end
102
+
103
+ its(:name) { should == "name" }
104
+ its(:type) { should == "string" }
105
+ its(:mysql_type) { should == "VARCHAR(255)" }
106
+ end
107
+
108
+ context "when attribute is text" do
109
+ let(:args) { ["user","name:text"] }
110
+
111
+ subject do
112
+ scaffolder.run(args)
113
+ scaffolder.attributes.first
114
+ end
115
+
116
+ its(:name) { should == "name" }
117
+ its(:type) { should == "text" }
118
+ its(:mysql_type) { should == "TEXT" }
119
+ end
120
+
121
+ context "when attribute is text" do
122
+ let(:args) { ["user","name:integer"] }
123
+
124
+ subject do
125
+ scaffolder.run(args)
126
+ scaffolder.attributes.first
127
+ end
128
+
129
+ its(:name) { should == "name" }
130
+ its(:type) { should == "integer" }
131
+ its(:mysql_type) { should == "INT" }
132
+ end
133
+
134
+ context "creating files" do
135
+ let(:args) { ["user","name:integer"] }
136
+
137
+ subject { scaffolder.run(args) }
138
+
139
+ it { File.should be_file(File.join(Dir.pwd,"/application/controllers/user.php")) }
140
+ it { File.should be_file(File.join(Dir.pwd,"/application/models/user_model.php")) }
141
+ it { File.should be_file(File.join(Dir.pwd,"/application/migrations/create_user.sql")) }
142
+ it { File.should be_file(File.join(Dir.pwd,"/application/views/user/create.php")) }
143
+ it { File.should be_file(File.join(Dir.pwd,"/application/views/user/index.php")) }
144
+ end
145
+ end
146
+ end
147
+ end
148
+ end
149
+ end
150
+ end
@@ -0,0 +1,55 @@
1
+ require "spec_helper"
2
+
3
+ describe CodeigniterScaffold::Executor do
4
+
5
+ let(:executor) { CodeigniterScaffold::Executor.new }
6
+
7
+ context "when arguments are not sent" do
8
+ it "show help for user" do
9
+ executor.run(nil).should == CodeigniterScaffold::Command::Help.new.run(nil)
10
+ end
11
+ end
12
+ context "when arguments are sent" do
13
+ after(:all) do
14
+ unziped = ["application","index.php","system"]
15
+ unziped.each { |f| FileUtils.rm_rf Dir.glob(f) }
16
+ end
17
+
18
+ context "and argument is '-h'" do
19
+ it "show help for user" do
20
+ executor.run(['-h']).should == CodeigniterScaffold::Command::Help.new.run(['-h'])
21
+ end
22
+ end
23
+
24
+ context "and argument is '--help'" do
25
+ it "show help for user" do
26
+ executor.run(['--help']).should == CodeigniterScaffold::Command::Help.new.run(['--help'])
27
+ end
28
+ end
29
+
30
+ context "and argument is '-i'" do
31
+ it "unzip codeigniter for user" do
32
+ executor.run(['-i']).should == CodeigniterScaffold::Command::Init.new.run(['-i'])
33
+ end
34
+ end
35
+
36
+ context "and argument is '--init'" do
37
+ it "unzip codeigniter for user" do
38
+ executor.run(['--init']).should == CodeigniterScaffold::Command::Init.new.run(['-init'])
39
+ end
40
+ end
41
+
42
+ context "and argument is '-s'" do
43
+ it "unzip codeigniter for user" do
44
+ executor.run(['-s']).should == CodeigniterScaffold::Command::Scaffold.new.run(['-s'])
45
+ end
46
+ end
47
+
48
+ context "and argument is '--scaffold'" do
49
+ it "unzip codeigniter for user" do
50
+ executor.run(['--scaffold']).should == CodeigniterScaffold::Command::Scaffold.new.run(['--scaffold'])
51
+ end
52
+ end
53
+
54
+ end
55
+ end
@@ -0,0 +1,7 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
4
+ require 'rspec'
5
+ require 'fileutils'
6
+ require File.dirname(__FILE__) + '/../lib/codeigniter_scaffold'
7
+ #require 'ruby-debug'
metadata ADDED
@@ -0,0 +1,216 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: codeigniter3-scaffold
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.0
5
+ platform: ruby
6
+ authors:
7
+ - jlamim
8
+ - universidadecodeigniter
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2016-09-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rubyzip
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ! '>='
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ! '>='
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: linecache19
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ! '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ! '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: ruby-debug-base19x
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ~>
47
+ - !ruby/object:Gem::Version
48
+ version: 0.11.30.pre4
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: 0.11.30.pre4
56
+ - !ruby/object:Gem::Dependency
57
+ name: ruby-debug19
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: shoulda
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ! '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: rdoc
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ~>
89
+ - !ruby/object:Gem::Version
90
+ version: '3.12'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ~>
96
+ - !ruby/object:Gem::Version
97
+ version: '3.12'
98
+ - !ruby/object:Gem::Dependency
99
+ name: bundler
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ~>
103
+ - !ruby/object:Gem::Version
104
+ version: 1.1.4
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ~>
110
+ - !ruby/object:Gem::Version
111
+ version: 1.1.4
112
+ - !ruby/object:Gem::Dependency
113
+ name: jeweler
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ~>
117
+ - !ruby/object:Gem::Version
118
+ version: 1.8.4
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ~>
124
+ - !ruby/object:Gem::Version
125
+ version: 1.8.4
126
+ - !ruby/object:Gem::Dependency
127
+ name: simplecov
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ! '>='
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ type: :development
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ! '>='
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ - !ruby/object:Gem::Dependency
141
+ name: rspec
142
+ requirement: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ! '>='
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ type: :development
148
+ prerelease: false
149
+ version_requirements: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ! '>='
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ description: Simple scaffold generator for codeigniter 3.1.0 now using Twitter Bootstrap
155
+ templates!
156
+ email: contato@universidadecodeigniter.com.br
157
+ executables:
158
+ - codeigniter3-scaffold
159
+ extensions: []
160
+ extra_rdoc_files:
161
+ - LICENSE.txt
162
+ - README
163
+ - README.md
164
+ files:
165
+ - .travis.yml
166
+ - Gemfile
167
+ - Gemfile.lock
168
+ - LICENSE.txt
169
+ - README
170
+ - README.md
171
+ - Rakefile
172
+ - VERSION
173
+ - bin/codeigniter3-scaffold
174
+ - codeigniter3-scaffold.gemspec
175
+ - lib/codeigniter_scaffold.rb
176
+ - lib/codeigniter_scaffold/attribute.rb
177
+ - lib/codeigniter_scaffold/command/help.rb
178
+ - lib/codeigniter_scaffold/command/init.rb
179
+ - lib/codeigniter_scaffold/command/scaffold.rb
180
+ - lib/codeigniter_scaffold/executor.rb
181
+ - lib/resources/ci_3.1.0.zip
182
+ - lib/resources/controller.php
183
+ - lib/resources/migration.sql
184
+ - lib/resources/model.php
185
+ - lib/resources/view_create.php
186
+ - lib/resources/view_index.php
187
+ - spec/codeigniter_scaffold/command/help_spec.rb
188
+ - spec/codeigniter_scaffold/command/init_spec.rb
189
+ - spec/codeigniter_scaffold/command/scaffold_spec.rb
190
+ - spec/codeigniter_scaffold/executor_spec.rb
191
+ - spec/spec_helper.rb
192
+ homepage: http://github.com/universidadecodeigniter/codeigniter-scaffold
193
+ licenses:
194
+ - MIT
195
+ metadata: {}
196
+ post_install_message:
197
+ rdoc_options: []
198
+ require_paths:
199
+ - lib
200
+ required_ruby_version: !ruby/object:Gem::Requirement
201
+ requirements:
202
+ - - ! '>='
203
+ - !ruby/object:Gem::Version
204
+ version: '0'
205
+ required_rubygems_version: !ruby/object:Gem::Requirement
206
+ requirements:
207
+ - - ! '>='
208
+ - !ruby/object:Gem::Version
209
+ version: '0'
210
+ requirements: []
211
+ rubyforge_project:
212
+ rubygems_version: 2.4.8
213
+ signing_key:
214
+ specification_version: 4
215
+ summary: Simple gem for generate scaffolds for codeigniter 3
216
+ test_files: []