larator 0.1.0 → 0.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ba688cf6c32c79736f1fe3b734c730ad8291391d
4
- data.tar.gz: ad3a6b8d11274baa27ffb529f8d6d415be287ee6
3
+ metadata.gz: 4b4aa118a4c2d86fe00e2c4ef6d00bd6b17de931
4
+ data.tar.gz: 06e58cfb4aae3dcd3b96eb83bfa9986cce03f3f4
5
5
  SHA512:
6
- metadata.gz: a3462982f9dd3d76db11423b0b95d6fddf47f371b7be7493eea0b13fd3bc5cfc14830fae76859f6512e8e7cf13da6b3b5d495b3d801175c2175d9c6ca7d18e71
7
- data.tar.gz: 908f01da0494cdcc29c909524fab47ea4e5aad08bf6021db0348ba780936f64a93cad3a0969d5c3a34d878f4a52cde63059f859b972f8a3bd65045e4a315f7c3
6
+ metadata.gz: 95acf3cd919fb685348809133f5e38ae9f28beaeed13a7b29d97ab176d8a9dacdfee6df1bf6ab5242b4aa45e525b8ac990ce30d86788aed1185eeffbab277b04
7
+ data.tar.gz: bdab5ba7a58ae75c95d0ce5242168060958b08a36e3a33deed535be8845f392271c8153eaa133857a585bbe3e72e2be103a76516a463328aadf38d3ba27f4337
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Larator
2
2
 
3
+ [![Build Status](https://travis-ci.org/guiltry/larator.svg?branch=master)](https://travis-ci.org/guiltry/larator)
4
+ [![Gem Version](https://badge.fury.io/rb/larator.svg)](http://badge.fury.io/rb/larator)
5
+
6
+
3
7
  The main purpose of this generator are:
4
8
 
5
9
  1. Give an idea to newcomers how to create a simple CRUD application
@@ -3,6 +3,17 @@ require "larator/generate"
3
3
 
4
4
  module Larator
5
5
  class CLI < Thor
6
+ include Thor::Actions
7
+
8
+ def self.source_root
9
+ File.dirname(__FILE__) + "/templates"
10
+ end
11
+
12
+ desc "generate larator config file", "Generate "
13
+ def init
14
+ template("init.tt", ".larator.yml")
15
+ end
16
+
6
17
  desc "generate GENERATOR", "Generate "
7
18
  subcommand "generate", Larator::Generate
8
19
  end
@@ -1,12 +1,26 @@
1
+ require 'yaml'
2
+
1
3
  module Larator
2
4
  class Generate < Thor
3
5
 
4
6
  desc "scaffold NAME", "Generate "
5
- method_option :harry
7
+ method_option :controller_location, type: :string
8
+ method_option :controller_namespace, type: :string
9
+ method_option :model_location, type: :string
10
+ method_option :model_namespace, type: :string
11
+ method_option :view_location, type: :string
6
12
  def scaffold(name)
7
13
  require "larator/generators/scaffold"
8
14
  Larator::Generators::Scaffold.start([name, options])
9
15
  end
16
+
17
+ private
18
+ def options
19
+ original_options = super
20
+ return original_options unless File.exists?(".larator.yml")
21
+ defaults = ::YAML::load_file(".larator.yml") || {}
22
+ Thor::CoreExt::HashWithIndifferentAccess.new(defaults.merge(original_options))
23
+ end
10
24
  end
11
25
  end
12
26
 
@@ -40,6 +40,54 @@ module Larator
40
40
  class_name.pluralize.underscore
41
41
  end
42
42
 
43
+ #############
44
+ ## OPTIONS ##
45
+ #############
46
+
47
+ # Controller #
48
+
49
+ # --controller-location=app/Http/Controllers/
50
+ def controller_location
51
+ folder_format(opt['controller_location']) || "app/Http/Controllers/"
52
+ end
53
+
54
+ # --controller-namespace=App\\Http\\Controllers
55
+ def controller_namespace
56
+ namespace_format(opt['controller_namespace']) || "App\\Http\\Controllers"
57
+ end
58
+
59
+ # Model #
60
+
61
+ # --model-location=app/
62
+ def model_location
63
+ folder_format(opt['model_location']) || "app/"
64
+ end
65
+
66
+ # --model-namespace=App
67
+ def model_namespace
68
+ namespace_format(opt['model_namespace']) || "App"
69
+ end
70
+
71
+ # View #
72
+
73
+ # --model-location=App
74
+ def view_location
75
+ folder_format(opt['view_location']) || "resources/views/"
76
+ end
77
+
78
+ ##########
79
+ ## UTIL ##
80
+ ##########
81
+
82
+ def folder_format(name)
83
+ return if name == nil
84
+ return name + '/'
85
+ end
86
+
87
+ def namespace_format(name)
88
+ return if name == nil
89
+ return name
90
+ end
43
91
  end
44
92
  end
45
93
  end
@@ -5,15 +5,15 @@ module Larator
5
5
  class Scaffold < Base
6
6
 
7
7
  def controller
8
- template("controller.tt", "app/Http/Controllers/#{controller_class_name}Controller.php")
8
+ template("controller.tt", "#{controller_location}#{controller_class_name}Controller.php")
9
9
  end
10
10
 
11
11
  def views
12
- template("views/index.tt", "resources/views/#{plular_table_name}/index.blade.php")
13
- template("views/create.tt", "resources/views/#{plular_table_name}/create.blade.php")
14
- template("views/show.tt", "resources/views/#{plular_table_name}/show.blade.php")
15
- template("views/edit.tt", "resources/views/#{plular_table_name}/edit.blade.php")
16
- template("views/_form.tt", "resources/views/#{plular_table_name}/_form.blade.php")
12
+ template("views/index.tt", "#{view_location}#{plular_table_name}/index.blade.php")
13
+ template("views/create.tt", "#{view_location}#{plular_table_name}/create.blade.php")
14
+ template("views/show.tt", "#{view_location}#{plular_table_name}/show.blade.php")
15
+ template("views/edit.tt", "#{view_location}#{plular_table_name}/edit.blade.php")
16
+ template("views/_form.tt", "#{view_location}#{plular_table_name}/_form.blade.php")
17
17
  end
18
18
 
19
19
  def request
@@ -21,7 +21,7 @@ module Larator
21
21
  end
22
22
 
23
23
  def model
24
- template("model.tt", "app/#{model_class_name}.php")
24
+ template("model.tt", "#{model_location}#{model_class_name}.php")
25
25
  end
26
26
 
27
27
  def migration
@@ -1,7 +1,7 @@
1
1
  <?php
2
- namespace App\Http\Controllers;
2
+ namespace <%= controller_namespace %>;
3
3
 
4
- use App\<%= model_class_name %>;
4
+ use <%= model_namespace %>\<%= model_class_name %>;
5
5
  use App\Http\Requests\<%= model_class_name %>Request;
6
6
  use App\Http\Controllers\Controller;
7
7
 
@@ -1,5 +1,5 @@
1
1
  <?php
2
- namespace App;
2
+ namespace <%= model_namespace %>;
3
3
 
4
4
  use Illuminate\Database\Eloquent\Model;
5
5
 
@@ -7,4 +7,4 @@ class <%= model_class_name %> extends Model
7
7
  {
8
8
  <%= "// Please change this value" %>
9
9
  protected $fillable = ['id'];
10
- }
10
+ }
@@ -0,0 +1,8 @@
1
+ # controller_location: "app/Http/Controllers"
2
+ # controller_namespace: "App\\Http\\Controllers"
3
+
4
+ # model_location: "app/"
5
+ # model_namespace: "App"
6
+
7
+ # view_location: "resources/views/"
8
+
@@ -1,3 +1,3 @@
1
1
  module Larator
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: larator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Harry Budianto
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-09-20 00:00:00.000000000 Z
11
+ date: 2015-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -144,6 +144,7 @@ files:
144
144
  - lib/larator/generators/templates/scaffold/default/views/edit.tt
145
145
  - lib/larator/generators/templates/scaffold/default/views/index.tt
146
146
  - lib/larator/generators/templates/scaffold/default/views/show.tt
147
+ - lib/larator/templates/init.tt
147
148
  - lib/larator/version.rb
148
149
  homepage: https://guiltry.github.io/larator/
149
150
  licenses: