likelion 0.1.2 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 882d3fd0b9fef34884e3826649c45214ac73511a
4
- data.tar.gz: 1fb3b6e745ec45442220eeb783ba607bd60eb143
3
+ metadata.gz: f5ebb93feabc10494cf074967fe9964f6da243bd
4
+ data.tar.gz: c12e982ad6002c26076b50fda60c1b7da1db55dc
5
5
  SHA512:
6
- metadata.gz: fd93b86cc1d393e26277ac58c312c8a35cb6b7b1b74c1878f6db51d1b712572948dd522360dc245c81fc7aedb13a009b8037392210cc393569cffc97eecf26d2
7
- data.tar.gz: edd9c6fe9f64172a870bdeef29d5791c87bd1761da6554d982b5be3d0594cf28a68362c8cf33a18e18928fa7150163e79b90c742e268bbfb5b5e44427610965b
6
+ metadata.gz: 8cbf55943ef32237e0215f32985ad768ab6be48ac32320d944b598f1f22c5f0052eae2dc1d655d93dafc70130893b7e181775a6939e1145b3981ea827c4b90ad
7
+ data.tar.gz: fe3be5be5afb6ba14787d7b83f2b503c2407bc312596bc2c13f118715a1ab3860728c809d0ca71c85d83321d48a40335b3d2de7570e3289eb765915d5e06e78e
data/README.md CHANGED
@@ -18,10 +18,6 @@ And then execute:
18
18
 
19
19
  $ bundle
20
20
 
21
- Or install it yourself as:
22
-
23
- $ gem install likelion
24
-
25
21
  ## Usage
26
22
 
27
23
  Gem을 설치한 후 아래와 같이 사용합니다.
@@ -33,6 +29,16 @@ Gem을 설치한 후 아래와 같이 사용합니다.
33
29
  $ rails generate likelion:install 160408
34
30
 
35
31
  와 같이 불러올 수 있습니다.
32
+ 생성 가능한 날짜의 목록은
33
+
34
+ $ rails generate likelion:install --help
35
+ ...
36
+ Description:
37
+ 현재 생성 가능한 날짜의 코드는
38
+ [160408]
39
+ 입니다.
40
+
41
+ 확인할 수 있습니다
36
42
 
37
43
  ## Contributing
38
44
  이 Gem은 누구든지 추가할 수 있습니다. 내용을 추가하기 위해선 생성하고자 하는 폴더의 상위 폴더에서 아래의 명령어를 실행합니다.
@@ -55,7 +61,7 @@ Gem의 파일 중 lib에 파일을 추가합니다. 구조는 아래와 같습
55
61
  ├── routes.rb
56
62
  ├── views.txt
57
63
  ├── [CONTROLLER_NAME].[METHOD].html.erb (ex. home.index.html.erb)
58
- ├── ....
64
+ ├── create_[MODEL.pluralize].rb (ex. create_posts.rb)
59
65
 
60
66
 
61
67
  - install_generator.rb
@@ -73,20 +79,20 @@ Templates 폴더는 'YYMMDD' 형식으로 된 날짜를 이름으로 갖는 폴
73
79
  rails g controller home
74
80
  ```
75
81
 
76
- - [CONTROLLER].rb : Controller 작성한 내용 중 <b>클래스의 메소드만</b> 작성한 것입니다. 각 라인마다 Tab으로 한 칸씩 띄워야하며 마지막 end 뒤에 Enter를 입력해 새로운 줄로 끝내야 합니다.
77
-
82
+ - [CONTROLLER].rb : Controller 전체 파일입니다.
78
83
 
79
84
  ```ruby
85
+ class HomeController < ApplicationController
80
86
  def index
81
87
  end
82
88
  def write
83
89
  @almond = params[:title]
84
90
  @anchovy = params[:content]
85
91
  end
86
-
92
+ end
87
93
  ```
88
94
 
89
- - routes.rb : routes.rb에 추가해야할 내용입니다. Devise는 자동으로 routes가 추가되므로 이 곳에 작성하지 않습니다. 마찬가지로 각 라인은 Tab으로 한 칸 띄우고 새로운 줄로 끝내야 합니다.
95
+ - routes.rb : routes.rb에 추가해야할 내용입니다. Devise는 자동으로 routes가 추가되므로 이 곳에 작성하지 않습니다. 각 라인은 Tab으로 한 칸 띄우고 새로운 줄로 끝내야 합니다.
90
96
 
91
97
 
92
98
  ```ruby
@@ -126,14 +132,30 @@ home.write.html.erb
126
132
  </div>
127
133
  ```
128
134
 
135
+ - create_[MODEL.pluralize].rb : 모델 데이터베이스 Migration 파일입니다.
136
+
137
+ ```ruby
138
+ class CreatePosts < ActiveRecord::Migration
139
+ def change
140
+ create_table :posts do |t|
141
+ t.string "title"
142
+ t.string "content"
143
+ t.timestamps null: false
144
+ end
145
+ end
146
+ end
147
+ ```
148
+
129
149
  #### 생성 순서
130
150
  create_templates::process에서 실행되며 순서는 아래와 같습니다.
131
151
 
132
- 1. views.txt를 한 줄 씩 읽으며 view를 추가합니다.
133
- 2. command.txt를 한 줄 씩 읽으며 model과 controller를 생성합니다.
134
- 3. application_controller.rb protect_from_forgery를 주석 처리합니다.
135
- 4. Bootstrap CDN을 application.html.erb에 추가합니다.
136
- 5. routes.rb 읽어 routes 설정을 합니다.
152
+
153
+ 1. command.txt를 한 줄 씩 읽으며 model과 controller를 생성합니다.
154
+ 2. 마이그레이션 파일을 추가합니다.
155
+ 3. views.txt를 씩 읽으며 view를 추가합니다.
156
+ 4. application_controller.rb protect_from_forgery를 주석 처리합니다.
157
+ 5. Bootstrap CDN을 application.html.erb에 추가합니다.
158
+ 6. routes.rb를 읽어 routes 설정을 합니다.
137
159
 
138
160
  ## Testing
139
161
  추가한 코드가 제대로 동작하는지 테스트해볼 수 있습니다. 작성한 파일의 Commit을 완료한 상태에서
@@ -1,8 +1,8 @@
1
1
  Description:
2
- Explain the generator
2
+ 현재 생성 가능한 날짜의 코드는
3
+ [160408, 160411]
4
+ 입니다.
3
5
 
4
6
  Example:
5
- rails generate likelion Thing
7
+ rails generate likelion:install 160408
6
8
 
7
- This will create:
8
- what/will/it/create
@@ -1,4 +1,5 @@
1
1
  require 'thor'
2
+ require 'rails'
2
3
  class CreateTemplates < Thor::Group
3
4
  include Thor::Actions
4
5
 
@@ -11,17 +12,18 @@ class CreateTemplates < Thor::Group
11
12
 
12
13
  def process
13
14
  source_paths << @@path
14
- #view 생성
15
- copy_files
16
15
  #모델, 컨트롤러 등 생성
17
16
  run_commands
17
+
18
+ #view 생성
19
+ create_views
20
+
18
21
  #application_controller.rb 주석 처리
19
22
  comment_application_controller
20
23
  #bootstrap 추가
21
24
  add_bootstraps
22
25
  #routes.rb 설정
23
26
  set_routes
24
-
25
27
  end
26
28
 
27
29
  def run_commands
@@ -40,21 +42,35 @@ class CreateTemplates < Thor::Group
40
42
  end
41
43
  end
42
44
 
45
+ def copy_file(src, dest)
46
+ "cp -rf #{src} #{dest}"
47
+ end
43
48
  def add_attributes(line)
44
49
  #TODO : Devise는...?
45
50
  # Thor::Actions::inject_into_class
46
51
  line = line.split
47
52
  if line[2].eql?"controller"
48
- inject_into_class "app/controllers/#{line[3]}_controller.rb", \
49
- "#{line[3].capitalize}Controller", \
50
- File.read("#{@@path}/#{line[3]}_controller.rb")
53
+ run(copy_file("#{@@path}/#{line[3]}_controller.rb", \
54
+ "app/controllers/#{line[3]}_controller.rb"))
51
55
  elsif line[2].eql?"model"
52
- inject_into_class "app/models/#{line[3]}.rb", \
53
- "#{line[3].capitalize}", \
54
- File.read("#{@@path}/#{line[3].capitalize}.rb")
56
+ if File.exist?("#{@@path}/#{line[3]}.rb")
57
+ run(copy_file("#{@@path}/#{line[3]}.rb", \
58
+ "app/models/#{line[3]}.rb"))
59
+ end
60
+ #데이터베이스 설정
61
+ set_database(line[3].pluralize)
55
62
  end
56
63
  end
57
64
 
65
+ def set_database(model_name)
66
+ if not File.exist?("#{@@path}/create_#{model_name}.rb")
67
+ return
68
+ end
69
+ db_file = Dir['db/migrate/*'].select { |f| f =~ /#{model_name}.rb$/ }
70
+ run(copy_file("#{@@path}/create_#{model_name}.rb",db_file[0]))
71
+ end
72
+
73
+
58
74
  def comment_application_controller
59
75
  # appication_controller.rb에 protect_from_forgery 주석 처리
60
76
  # Thor::Actions::comment_lines
@@ -80,18 +96,16 @@ class CreateTemplates < Thor::Group
80
96
 
81
97
  def set_routes
82
98
  #routes.rb 내용을 복사
83
- # Thor::Actions::insert_into_file
84
- insert_into_file "config/routes.rb", \
85
- File.read("#{@@path}/routes.rb"), \
86
- :after => "Rails.application.routes.draw do\n"
99
+ run(copy_file("#{@@path}/routes.rb", "config/routes.rb"))
87
100
  end
88
101
 
89
- def copy_files
102
+ def create_views
90
103
  File.open("#{@@path}/views.txt","r") do |infile|
91
104
  while(filename = infile.gets)
92
105
  filename.rstrip!
93
106
  controller, view = filename.split('.',2)
94
- template filename, "app/views/#{controller}/#{view}"
107
+ run(copy_file("#{@@path}/#{filename}", \
108
+ "app/views/#{controller}/#{view}"))
95
109
  end
96
110
  end
97
111
  end
@@ -1,10 +1,9 @@
1
1
  module Likelion
2
2
  class InstallGenerator < Rails::Generators::NamedBase
3
- desc "This generator creates an initializer file at config/initializers"
4
-
3
+ @@path = File.dirname(__FILE__)
4
+ desc File.read("#{@@path}/USAGE")
5
5
  def copy_snippet
6
- path = File.dirname(__FILE__)
7
- run("ruby #{path}/create_templates.rb #{file_name}")
6
+ run("ruby #{@@path}/create_templates.rb #{file_name}")
8
7
  end
9
8
  end
10
9
  end
@@ -7,7 +7,7 @@
7
7
  </div>
8
8
  <div class="form-group">
9
9
  <label for="exampleInputPassword1">글 내용</label>
10
- <textarea name="content" class="form-control" id="exampleInputPassword1">
10
+ <textarea name="content" class="form-control" id="exampleInputPassword1"></textarea>
11
11
  </div>
12
12
  <button type="submit" class="btn btn-default">전송완료</button>
13
13
  </form>
@@ -1,6 +1,8 @@
1
+ class HomeController < ApplicationController
1
2
  def index
2
3
  end
3
4
  def write
4
5
  @almond = params[:title]
5
6
  @anchovy = params[:content]
6
7
  end
8
+ end
@@ -1,4 +1,60 @@
1
+ Rails.application.routes.draw do
1
2
  root 'home#index'
2
3
 
3
4
  get '/' => 'home#index'
4
5
  post '/write' => 'home#write'
6
+ # The priority is based upon order of creation: first created -> highest priority.
7
+ # See how all your routes lay out with "rake routes".
8
+
9
+ # You can have the root of your site routed with "root"
10
+ # root 'welcome#index'
11
+
12
+ # Example of regular route:
13
+ # get 'products/:id' => 'catalog#view'
14
+
15
+ # Example of named route that can be invoked with purchase_url(id: product.id)
16
+ # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase
17
+
18
+ # Example resource route (maps HTTP verbs to controller actions automatically):
19
+ # resources :products
20
+
21
+ # Example resource route with options:
22
+ # resources :products do
23
+ # member do
24
+ # get 'short'
25
+ # post 'toggle'
26
+ # end
27
+ #
28
+ # collection do
29
+ # get 'sold'
30
+ # end
31
+ # end
32
+
33
+ # Example resource route with sub-resources:
34
+ # resources :products do
35
+ # resources :comments, :sales
36
+ # resource :seller
37
+ # end
38
+
39
+ # Example resource route with more complex sub-resources:
40
+ # resources :products do
41
+ # resources :comments
42
+ # resources :sales do
43
+ # get 'recent', on: :collection
44
+ # end
45
+ # end
46
+
47
+ # Example resource route with concerns:
48
+ # concern :toggleable do
49
+ # post 'toggle'
50
+ # end
51
+ # resources :posts, concerns: :toggleable
52
+ # resources :photos, concerns: :toggleable
53
+
54
+ # Example resource route within a namespace:
55
+ # namespace :admin do
56
+ # # Directs /admin/products/* to Admin::ProductsController
57
+ # # (app/controllers/admin/products_controller.rb)
58
+ # resources :products
59
+ # end
60
+ end
@@ -0,0 +1,2 @@
1
+ rails g controller home index
2
+ gem install mailgun-ruby
@@ -0,0 +1,18 @@
1
+ <div class="container">
2
+ <h1>이메일 보내는 페이지 입니다.</h1>
3
+ <form action="/write" method="POST">
4
+ <div class="form-group">
5
+ <label for="exampleInputTitle1">메일 제목</label>
6
+ <input name = "title" type="text" class="form-control" id="exampleInputTitle1" placeholder="제목을 써 주세요.">
7
+ </div>
8
+ <div class="form-group">
9
+ <label for="exampleInputEmail1">받는 사람</label>
10
+ <input name = "email" type="email" class="form-control" id="exampleInputEmail1" placeholder="master@likelion.net">
11
+ </div>
12
+ <div class="form-group">
13
+ <label for="exampleInputPassword1">메일 내용</label>
14
+ <textarea name="content" class="form-control" id="exampleInputPassword1" rows"5" id="comment" placeholder="글을 입력해주세요."></textarea>
15
+ </div>
16
+ <button type="submit" class="btn btn-default">전송</button>
17
+ </form>
18
+ </div>
@@ -0,0 +1,8 @@
1
+ <h1>메일이 보내졌습니다</h1>
2
+
3
+ <h2>여러분이 쓴 메일의 제목은</h2>
4
+ <%= @title %>
5
+ <h2>여러분이 쓴 메일의 받는사람은</h2>
6
+ <%= @receiver %>
7
+ <h2>여러분이 쓴 글의 내용은</h2>
8
+ <%= @content %>
@@ -0,0 +1,24 @@
1
+ require 'mailgun'
2
+
3
+ class HomeController < ApplicationController
4
+ def index
5
+ end
6
+ def write
7
+ @title = params[:title]
8
+ @receiver = params[:email]
9
+ @content = params[:content]
10
+ #mail_sending
11
+ mg_client = Mailgun::Client.new("Api key")
12
+ message_params = {
13
+ from: 'master@example.com',
14
+ to: @receiver,
15
+ subject: @title,
16
+ text: @content
17
+ }
18
+
19
+ result = mg_client.send_message('샌드박스', message_params).to_h!
20
+
21
+ message_id = result['id']
22
+ message = result['message']
23
+ end
24
+ end
@@ -0,0 +1,60 @@
1
+ Rails.application.routes.draw do
2
+ root 'home#index'
3
+
4
+ get '/' => 'home#index'
5
+ post '/write' => 'home#write'
6
+ # The priority is based upon order of creation: first created -> highest priority.
7
+ # See how all your routes lay out with "rake routes".
8
+
9
+ # You can have the root of your site routed with "root"
10
+ # root 'welcome#index'
11
+
12
+ # Example of regular route:
13
+ # get 'products/:id' => 'catalog#view'
14
+
15
+ # Example of named route that can be invoked with purchase_url(id: product.id)
16
+ # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase
17
+
18
+ # Example resource route (maps HTTP verbs to controller actions automatically):
19
+ # resources :products
20
+
21
+ # Example resource route with options:
22
+ # resources :products do
23
+ # member do
24
+ # get 'short'
25
+ # post 'toggle'
26
+ # end
27
+ #
28
+ # collection do
29
+ # get 'sold'
30
+ # end
31
+ # end
32
+
33
+ # Example resource route with sub-resources:
34
+ # resources :products do
35
+ # resources :comments, :sales
36
+ # resource :seller
37
+ # end
38
+
39
+ # Example resource route with more complex sub-resources:
40
+ # resources :products do
41
+ # resources :comments
42
+ # resources :sales do
43
+ # get 'recent', on: :collection
44
+ # end
45
+ # end
46
+
47
+ # Example resource route with concerns:
48
+ # concern :toggleable do
49
+ # post 'toggle'
50
+ # end
51
+ # resources :posts, concerns: :toggleable
52
+ # resources :photos, concerns: :toggleable
53
+
54
+ # Example resource route within a namespace:
55
+ # namespace :admin do
56
+ # # Directs /admin/products/* to Admin::ProductsController
57
+ # # (app/controllers/admin/products_controller.rb)
58
+ # resources :products
59
+ # end
60
+ end
@@ -0,0 +1,2 @@
1
+ home.index.html.erb
2
+ home.write.html.erb
@@ -0,0 +1,2 @@
1
+ rails g controller home index
2
+ rails g model post
@@ -0,0 +1,11 @@
1
+ class CreatePosts < ActiveRecord::Migration
2
+ def change
3
+ create_table :posts do |t|
4
+
5
+ t.string "title"
6
+ t.string "content"
7
+
8
+ t.timestamps null: false
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ <h1>hi</h1>
2
+ <div class="container">
3
+ <form action="/write" method="POST">
4
+ <div class="form-group">
5
+ <label for="exampleInputEmail1">제목</label>
6
+ <input type="text" name="title" class="form-control" id="exampleInputEmail1" placeholder="제목">
7
+ </div>
8
+ <label for="exampleInputEmail1">내용</label>
9
+ <textarea name="content" class="form-control" rows="5" id="commit"></textarea>
10
+ <button type="submit" class="btn btn-default" style="margin-top:20px">전송</button>
11
+ </form>
12
+ </div>
@@ -0,0 +1,8 @@
1
+ <h2>여기는 지난 게시판 글입니다.</h2>
2
+ <% @every_post.each do |p| %>
3
+ <%= p.title %>
4
+ <%= p.content %>
5
+ <%= p.created_at %>
6
+ <hr>
7
+ <% end %>
8
+ <h1><a href="/">게시판 글 쓰러 가기</a></h1>
@@ -0,0 +1,2 @@
1
+ <%= @title %>
2
+ <%= @content %>
@@ -0,0 +1,21 @@
1
+ class HomeController < ApplicationController
2
+ def index
3
+ end
4
+
5
+ def write
6
+ @title = params[:title]
7
+ @content = params[:content]
8
+
9
+ new_post = Post.new
10
+ new_post.title = @title
11
+ new_post.content = @content
12
+ new_post.save
13
+
14
+ redirect_to "/list"
15
+
16
+ end
17
+
18
+ def list
19
+ @every_post = Post.all.order("id desc")
20
+ end
21
+ end
@@ -0,0 +1,61 @@
1
+ Rails.application.routes.draw do
2
+ root 'home#index'
3
+ get 'home/index'
4
+ post 'write' => "home#write"
5
+ get '/list' => "home#list"
6
+
7
+ # The priority is based upon order of creation: first created -> highest priority.
8
+ # See how all your routes lay out with "rake routes".
9
+
10
+ # You can have the root of your site routed with "root"
11
+ # root 'welcome#index'
12
+
13
+ # Example of regular route:
14
+ # get 'products/:id' => 'catalog#view'
15
+
16
+ # Example of named route that can be invoked with purchase_url(id: product.id)
17
+ # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase
18
+
19
+ # Example resource route (maps HTTP verbs to controller actions automatically):
20
+ # resources :products
21
+
22
+ # Example resource route with options:
23
+ # resources :products do
24
+ # member do
25
+ # get 'short'
26
+ # post 'toggle'
27
+ # end
28
+ #
29
+ # collection do
30
+ # get 'sold'
31
+ # end
32
+ # end
33
+
34
+ # Example resource route with sub-resources:
35
+ # resources :products do
36
+ # resources :comments, :sales
37
+ # resource :seller
38
+ # end
39
+
40
+ # Example resource route with more complex sub-resources:
41
+ # resources :products do
42
+ # resources :comments
43
+ # resources :sales do
44
+ # get 'recent', on: :collection
45
+ # end
46
+ # end
47
+
48
+ # Example resource route with concerns:
49
+ # concern :toggleable do
50
+ # post 'toggle'
51
+ # end
52
+ # resources :posts, concerns: :toggleable
53
+ # resources :photos, concerns: :toggleable
54
+
55
+ # Example resource route within a namespace:
56
+ # namespace :admin do
57
+ # # Directs /admin/products/* to Admin::ProductsController
58
+ # # (app/controllers/admin/products_controller.rb)
59
+ # resources :products
60
+ # end
61
+ end
@@ -0,0 +1,3 @@
1
+ home.index.html.erb
2
+ home.list.html.erb
3
+ home.write.html.erb
@@ -1,3 +1,3 @@
1
1
  module Likelion
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: likelion
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ChangHee Lee
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-05-26 00:00:00.000000000 Z
11
+ date: 2016-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: devise
@@ -119,6 +119,20 @@ files:
119
119
  - lib/generators/likelion/templates/160408/home_controller.rb
120
120
  - lib/generators/likelion/templates/160408/routes.rb
121
121
  - lib/generators/likelion/templates/160408/views.txt
122
+ - lib/generators/likelion/templates/160411/command.txt
123
+ - lib/generators/likelion/templates/160411/home.index.html.erb
124
+ - lib/generators/likelion/templates/160411/home.write.html.erb
125
+ - lib/generators/likelion/templates/160411/home_controller.rb
126
+ - lib/generators/likelion/templates/160411/routes.rb
127
+ - lib/generators/likelion/templates/160411/views.txt
128
+ - lib/generators/likelion/templates/160413/command.txt
129
+ - lib/generators/likelion/templates/160413/create_posts.rb
130
+ - lib/generators/likelion/templates/160413/home.index.html.erb
131
+ - lib/generators/likelion/templates/160413/home.list.html.erb
132
+ - lib/generators/likelion/templates/160413/home.write.html.erb
133
+ - lib/generators/likelion/templates/160413/home_controller.rb
134
+ - lib/generators/likelion/templates/160413/routes.rb
135
+ - lib/generators/likelion/templates/160413/views.txt
122
136
  - lib/likelion.rb
123
137
  - lib/likelion/version.rb
124
138
  - likelion.gemspec