likelion 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 33ab1cd13a2c38f8f55b28cb2b6f524b4ea9c324
4
- data.tar.gz: d25c703eec6d504dc7535bb7bf57820878fe5162
3
+ metadata.gz: 882d3fd0b9fef34884e3826649c45214ac73511a
4
+ data.tar.gz: 1fb3b6e745ec45442220eeb783ba607bd60eb143
5
5
  SHA512:
6
- metadata.gz: 6a1033bab43328a380bc92267b380d896b2431e16c98101901185ca019e4431f5da8065f867e5728755a0818e9d17a275998d31fe03cd6aa436a721662a4afcf
7
- data.tar.gz: 772418f9bf5ca6cf772d704a05b54197b4f13188bf3ea97f22fee3db020146d2094682eb01b59e6d76d5ef4b2359f425a222295996c830f2aa5f97cf6011ee14
6
+ metadata.gz: fd93b86cc1d393e26277ac58c312c8a35cb6b7b1b74c1878f6db51d1b712572948dd522360dc245c81fc7aedb13a009b8037392210cc393569cffc97eecf26d2
7
+ data.tar.gz: edd9c6fe9f64172a870bdeef29d5791c87bd1761da6554d982b5be3d0594cf28a68362c8cf33a18e18928fa7150163e79b90c742e268bbfb5b5e44427610965b
data/README.md CHANGED
@@ -1,4 +1,9 @@
1
1
  # Likelion
2
+ 멋쟁이 사자처럼 수업 때 사용된 코드들을 생성하는 Gem 입니다.
3
+ 수업 종료할 때 작성된 코드를 생성합니다.
4
+
5
+ ## Dependency
6
+ - Ruby >= 2.1.2
2
7
 
3
8
 
4
9
  ## Installation
@@ -24,11 +29,165 @@ Gem을 설치한 후 아래와 같이 사용합니다.
24
29
  $ rails generate likelion:install [날짜]
25
30
 
26
31
  날짜는 'YYMMDD' 형식으로 입력됩니다. 예를 들어 16년 4월 8일에 진행된 수업의 코드는
32
+
27
33
  $ rails generate likelion:install 160408
28
34
 
29
35
  와 같이 불러올 수 있습니다.
30
36
 
31
37
  ## Contributing
38
+ 이 Gem은 누구든지 추가할 수 있습니다. 내용을 추가하기 위해선 생성하고자 하는 폴더의 상위 폴더에서 아래의 명령어를 실행합니다.
39
+
40
+ $ git clone 'https://github.com/LEECHHE/likelion'
41
+ $ cd likelion
42
+
43
+ Gem의 파일 중 lib에 파일을 추가합니다. 구조는 아래와 같습니다.
44
+
45
+ └── lib
46
+ └── generators
47
+ └── likelion
48
+ └── create_templates.rb
49
+ ├── install_generator.rb
50
+ ├── USAGE
51
+ └── templates
52
+ └── 160408
53
+ └── command.txt
54
+ ├── [CONTROLLER].rb (ex. home_controller.rb)
55
+ ├── routes.rb
56
+ ├── views.txt
57
+ ├── [CONTROLLER_NAME].[METHOD].html.erb (ex. home.index.html.erb)
58
+ ├── ....
59
+
60
+
61
+ - install_generator.rb
62
+ - create_templates.rb를 실행하며 rails generator를 생성합니다.
63
+
64
+ - create_templates.rb
65
+ - Model, Controller, View, 파일 복사 등을 담당합니다.
66
+
67
+ ### Templates
68
+ Templates 폴더는 'YYMMDD' 형식으로 된 날짜를 이름으로 갖는 폴더로 구성되어 있습니다. 이 날짜는 강의를 한 날짜에 해당합니다. 각 파일들은 위와 같이 5가지 종류의 파일로 구성되어 있습니다.
69
+ - command.txt : 커맨드 창에 직접 입력한 명령어 중 Model과 Controller 관련 내용입니다. ##은 주석으로 간주되며 실행하지 않습니다.
70
+
71
+ ```
72
+ ## 컨트롤러 생성
73
+ rails g controller home
74
+ ```
75
+
76
+ - [CONTROLLER].rb : Controller에 작성한 내용 중 <b>클래스의 메소드만</b> 작성한 것입니다. 각 라인마다 Tab으로 한 칸씩 띄워야하며 마지막 end 뒤에 Enter를 입력해 새로운 줄로 끝내야 합니다.
77
+
78
+
79
+ ```ruby
80
+ def index
81
+ end
82
+ def write
83
+ @almond = params[:title]
84
+ @anchovy = params[:content]
85
+ end
86
+
87
+ ```
88
+
89
+ - routes.rb : routes.rb에 추가해야할 내용입니다. Devise는 자동으로 routes가 추가되므로 이 곳에 작성하지 않습니다. 마찬가지로 각 라인은 Tab으로 한 칸 띄우고 새로운 줄로 끝내야 합니다.
90
+
91
+
92
+ ```ruby
93
+ root 'home#index'
94
+
95
+ get '/' => 'home#index'
96
+ post '/write' => 'home#write'
97
+
98
+
99
+ ```
100
+
101
+ - views.txt : view 파일들의 목록입니다. 주의할 점은 [컨트롤러 이름].[메소드 이름].html.erb 로 앞에 컨트롤러 이름이 추가된 점입니다. 예를 들어 home_controller.rb의 index 메소드와 연관된 view는 home.index.html.erb 입니다.
102
+
103
+
104
+ ```
105
+ home.index.html.erb
106
+ home.write.html.erb
107
+
108
+ ```
109
+
110
+ - [CONTROLLER_NAME].[METHOD].html.erb : View 파일입니다. 앞에 컨트롤러 이름이 붙는 것에 유의해주시기 바랍니다. 16년 4월 8일에 진행된 강의에서 index.html.erb는 아래와 같습니다.
111
+
112
+ ```erb
113
+ <div class="container">
114
+ <h1>게시판입니다.</h1>
115
+ <form action="/write" method="POST">
116
+ <div class="form-group">
117
+ <label for="exampleInputEmail1">글 제목</label>
118
+ <input type="text" class="form-control" id="exampleInputEmail1" name="title">
119
+ </div>
120
+ <div class="form-group">
121
+ <label for="exampleInputPassword1">글 내용</label>
122
+ <textarea name="content" class="form-control" id="exampleInputPassword1">
123
+ </div>
124
+ <button type="submit" class="btn btn-default">전송완료</button>
125
+ </form>
126
+ </div>
127
+ ```
128
+
129
+ #### 생성 순서
130
+ create_templates::process에서 실행되며 순서는 아래와 같습니다.
131
+
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 설정을 합니다.
137
+
138
+ ## Testing
139
+ 추가한 코드가 제대로 동작하는지 테스트해볼 수 있습니다. 작성한 파일의 Commit을 완료한 상태에서
140
+
141
+ $ gem build likelion.gemspec
142
+
143
+ 위 명령어를 입력하면 likelion-[VERSION].gem 이 생성됩니다. 2016년 5월 27일 기준으로 likelion-0.1.1.gem 이 생성됩니다. 새로운 rails application을 만들어 테스트해봅시다.
144
+
145
+ $ cd ..
146
+ $ rails new blog
147
+ $ cd ./blog
148
+
149
+ Gemfile 에 아래와 같은 내용을 추가합니다.
150
+ ```ruby
151
+ gem 'likelion', path:"../likelion"
152
+ ```
153
+ Gem을 설치합니다.
154
+
155
+ $ bundle install
156
+
157
+
158
+ 이제 만든 Gem을 테스트해볼 수 있습니다. Usage를 참고하여 아래와 같은 명령어를 입력합니다.
159
+
160
+ $ rails generate likelion:install 160408
161
+
162
+ 위 명령어의 날짜에 추가한 날의 날짜를 넣으면 아래와 같이 추가됩니다.
163
+
164
+ ```ruby
165
+ ➜ blog rails g likelion:install 160408
166
+ Running via Spring preloader in process 70972
167
+ run ruby /Users/leechhe/Documents/Development/likelion/lib/generators/likelion/create_templates.rb 160408 from "."
168
+ create app/views/home/index.html.erb
169
+ create app/views/home/write.html.erb
170
+ run rails g controller home from "."
171
+ Running via Spring preloader in process 70978
172
+ create app/controllers/home_controller.rb
173
+ invoke erb
174
+ exist app/views/home
175
+ invoke test_unit
176
+ create test/controllers/home_controller_test.rb
177
+ invoke helper
178
+ create app/helpers/home_helper.rb
179
+ invoke test_unit
180
+ invoke assets
181
+ invoke coffee
182
+ create app/assets/javascripts/home.coffee
183
+ invoke scss
184
+ create app/assets/stylesheets/home.scss
185
+ insert app/controllers/home_controller.rb
186
+ gsub app/controllers/application_controller.rb
187
+ insert app/views/layouts/application.html.erb
188
+ insert config/routes.rb
189
+ ```
190
+
32
191
 
33
192
  Bug reports and pull requests are welcome on GitHub at https://github.com/LEECHHE/likelion. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
34
193
 
@@ -1,15 +1,18 @@
1
- require 'Thor'
1
+ require 'thor'
2
2
  class CreateTemplates < Thor::Group
3
3
  include Thor::Actions
4
4
 
5
5
  raise ArgumentError, "The date should be input." if ARGV[0] == nil
6
6
  @@path = "#{File.dirname(__FILE__)}/templates/#{ARGV[0]}"
7
+
7
8
  def self.source_root
8
9
  File.dirname(__FILE__)
9
10
  end
10
11
 
11
12
  def process
12
13
  source_paths << @@path
14
+ #view 생성
15
+ copy_files
13
16
  #모델, 컨트롤러 등 생성
14
17
  run_commands
15
18
  #application_controller.rb 주석 처리
@@ -22,17 +25,14 @@ class CreateTemplates < Thor::Group
22
25
  end
23
26
 
24
27
  def run_commands
25
- # IO.readlines("#{path}/command.txt").each do |infile|
26
- #view 생성
27
- copy_files
28
- File.open([@@path,'command.txt'].join('/'),"r") do |infile|
28
+ File.open("#{@@path}/command.txt","r") do |infile|
29
29
  #command.txt 내에 있는 커맨드 읽기
30
30
  while( line = infile.gets )
31
31
  #주석은 통과
32
32
  if line[0] == '#'
33
33
  next
34
34
  end
35
- #Command 실행
35
+ #Command 실행. Thor::Actions::run(cmd)
36
36
  run (line)
37
37
  #Model과 Controller인 경우 내용(method, attributes 등) 추가
38
38
  add_attributes(line)
@@ -42,8 +42,9 @@ class CreateTemplates < Thor::Group
42
42
 
43
43
  def add_attributes(line)
44
44
  #TODO : Devise는...?
45
+ # Thor::Actions::inject_into_class
45
46
  line = line.split
46
- if line[2].eql?"controller"
47
+ if line[2].eql?"controller"
47
48
  inject_into_class "app/controllers/#{line[3]}_controller.rb", \
48
49
  "#{line[3].capitalize}Controller", \
49
50
  File.read("#{@@path}/#{line[3]}_controller.rb")
@@ -56,11 +57,13 @@ class CreateTemplates < Thor::Group
56
57
 
57
58
  def comment_application_controller
58
59
  # appication_controller.rb에 protect_from_forgery 주석 처리
60
+ # Thor::Actions::comment_lines
59
61
  comment_lines 'app/controllers/application_controller.rb', /protect_from_forgery with: :exception/
60
62
  end
61
63
 
62
64
  def add_bootstraps
63
65
  #Bootstrap CDN 추가
66
+ # Thor::Actions::insert_into_file
64
67
  insert_into_file "app/views/layouts/application.html.erb", bootstrap_cdn, :before => "</head>\n"
65
68
  end
66
69
 
@@ -72,15 +75,17 @@ class CreateTemplates < Thor::Group
72
75
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">
73
76
 
74
77
  <!-- Latest compiled and minified JavaScript -->
75
- <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>\n'
78
+ <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>'
76
79
  end
77
80
 
78
81
  def set_routes
79
82
  #routes.rb 내용을 복사
83
+ # Thor::Actions::insert_into_file
80
84
  insert_into_file "config/routes.rb", \
81
85
  File.read("#{@@path}/routes.rb"), \
82
86
  :after => "Rails.application.routes.draw do\n"
83
87
  end
88
+
84
89
  def copy_files
85
90
  File.open("#{@@path}/views.txt","r") do |infile|
86
91
  while(filename = infile.gets)
@@ -4,4 +4,3 @@
4
4
  @almond = params[:title]
5
5
  @anchovy = params[:content]
6
6
  end
7
-
@@ -1,4 +1,4 @@
1
1
  root 'home#index'
2
2
 
3
3
  get '/' => 'home#index'
4
- post '/write' => 'home#write'
4
+ post '/write' => 'home#write'
@@ -1,3 +1,3 @@
1
1
  module Likelion
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: likelion
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - ChangHee Lee
@@ -143,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
143
  version: '0'
144
144
  requirements: []
145
145
  rubyforge_project:
146
- rubygems_version: 2.2.2
146
+ rubygems_version: 2.4.5
147
147
  signing_key:
148
148
  specification_version: 4
149
149
  summary: "멋쟁이 사자처럼 수업 때 사용된 코드들을 쉽게 생성해줍니다."