change-log 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +3 -0
  4. data/Rakefile +40 -0
  5. data/app/assets/javascripts/change_log/application.js +15 -0
  6. data/app/assets/stylesheets/change_log/application.css +299 -0
  7. data/app/controllers/change_log/application_controller.rb +5 -0
  8. data/app/controllers/change_log/base_controller.rb +17 -0
  9. data/app/helpers/change_log/application_helper.rb +8 -0
  10. data/app/models/change_log/activerecord_model.rb +12 -0
  11. data/app/models/change_log/mongoid_model.rb +20 -0
  12. data/app/views/change_log/base/index.html.erb +5 -0
  13. data/app/views/layouts/change_log/application.html.erb +14 -0
  14. data/config/routes.rb +3 -0
  15. data/lib/change_log/config.rb +31 -0
  16. data/lib/change_log/engine.rb +10 -0
  17. data/lib/change_log/markdown_handler.rb +14 -0
  18. data/lib/change_log/version.rb +3 -0
  19. data/lib/change_log.rb +13 -0
  20. data/lib/generators/change_log/install_generator.rb +57 -0
  21. data/lib/generators/change_log/templates/initializer.erb +34 -0
  22. data/lib/generators/change_log/templates/migration.rb +20 -0
  23. data/lib/generators/change_log/utils.rb +49 -0
  24. data/lib/tasks/change_log_tasks.rake +85 -0
  25. data/test/change_log_test.rb +7 -0
  26. data/test/dummy/README.rdoc +261 -0
  27. data/test/dummy/Rakefile +7 -0
  28. data/test/dummy/app/assets/javascripts/application.js +15 -0
  29. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  30. data/test/dummy/app/controllers/application_controller.rb +3 -0
  31. data/test/dummy/app/helpers/application_helper.rb +2 -0
  32. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  33. data/test/dummy/config/application.rb +59 -0
  34. data/test/dummy/config/boot.rb +10 -0
  35. data/test/dummy/config/database.yml +25 -0
  36. data/test/dummy/config/environment.rb +5 -0
  37. data/test/dummy/config/environments/development.rb +37 -0
  38. data/test/dummy/config/environments/production.rb +67 -0
  39. data/test/dummy/config/environments/test.rb +37 -0
  40. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  41. data/test/dummy/config/initializers/inflections.rb +15 -0
  42. data/test/dummy/config/initializers/mime_types.rb +5 -0
  43. data/test/dummy/config/initializers/secret_token.rb +7 -0
  44. data/test/dummy/config/initializers/session_store.rb +8 -0
  45. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  46. data/test/dummy/config/locales/en.yml +5 -0
  47. data/test/dummy/config/routes.rb +4 -0
  48. data/test/dummy/config.ru +4 -0
  49. data/test/dummy/public/404.html +26 -0
  50. data/test/dummy/public/422.html +26 -0
  51. data/test/dummy/public/500.html +25 -0
  52. data/test/dummy/public/favicon.ico +0 -0
  53. data/test/dummy/script/rails +6 -0
  54. data/test/integration/navigation_test.rb +10 -0
  55. data/test/test_helper.rb +15 -0
  56. metadata +205 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6f90b7b9c038c413cacbe771d803c914012ae747
4
+ data.tar.gz: 6fced5cb988b66866d81b4050111b52773f5290b
5
+ SHA512:
6
+ metadata.gz: 31f31544b528c7cbac642bc4d94d77fa77ac8227d1b618cd7c4bb588b4ab2533730c190044c447f719c166be300a9e84f9d24c44495b36d94ce62af22edfcde9
7
+ data.tar.gz: 09d510fb2349e186ac8c11b2b8a70709746cfad29887d0b17ed25bda46cec64ac4ce16fdbc55a3d6c5460490f8d7cb70c77fa8b3c6f727164d55665746aae677
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2014 YOURNAME
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.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = ChangeLog
2
+
3
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'ChangeLog'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
24
+ load 'rails/tasks/engine.rake'
25
+
26
+
27
+
28
+ Bundler::GemHelper.install_tasks
29
+
30
+ require 'rake/testtask'
31
+
32
+ Rake::TestTask.new(:test) do |t|
33
+ t.libs << 'lib'
34
+ t.libs << 'test'
35
+ t.pattern = 'test/**/*_test.rb'
36
+ t.verbose = false
37
+ end
38
+
39
+
40
+ task :default => :test
@@ -0,0 +1,15 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // the compiled file.
9
+ //
10
+ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
+ // GO AFTER THE REQUIRES BELOW.
12
+ //
13
+ //= require jquery.min
14
+ //= require jquery_ujs
15
+ //= require_tree .
@@ -0,0 +1,299 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree
13
+ */
14
+
15
+ .markdown-body {
16
+ font-family: "Helvetica Neue",Helvetica,"Segoe UI",Arial,freesans,sans-serif;
17
+ font-size: 16px;
18
+ line-height: 1.6;
19
+ overflow: hidden;
20
+ word-wrap: break-word;
21
+ }
22
+ .markdown-body > *:first-child {
23
+ margin-top: 0 !important;
24
+ }
25
+ .markdown-body > *:last-child {
26
+ margin-bottom: 0 !important;
27
+ }
28
+ .markdown-body .absent {
29
+ color: #c00;
30
+ }
31
+ .markdown-body .anchor {
32
+ bottom: 0;
33
+ display: block;
34
+ left: 0;
35
+ margin-left: -30px;
36
+ padding-left: 30px;
37
+ padding-right: 6px;
38
+ position: absolute;
39
+ top: 0;
40
+ }
41
+ .markdown-body .anchor:focus {
42
+ outline: medium none;
43
+ }
44
+ .markdown-body h1, .markdown-body h2, .markdown-body h3, .markdown-body h4, .markdown-body h5, .markdown-body h6 {
45
+ font-weight: bold;
46
+ line-height: 1.4;
47
+ margin-bottom: 16px;
48
+ margin-top: 1em;
49
+ position: relative;
50
+ }
51
+ .markdown-body h1 .octicon-link, .markdown-body h2 .octicon-link, .markdown-body h3 .octicon-link, .markdown-body h4 .octicon-link, .markdown-body h5 .octicon-link, .markdown-body h6 .octicon-link {
52
+ color: #000;
53
+ display: none;
54
+ vertical-align: middle;
55
+ }
56
+ .markdown-body h1:hover .anchor, .markdown-body h2:hover .anchor, .markdown-body h3:hover .anchor, .markdown-body h4:hover .anchor, .markdown-body h5:hover .anchor, .markdown-body h6:hover .anchor {
57
+ line-height: 1;
58
+ margin-left: -30px;
59
+ padding-left: 8px;
60
+ text-decoration: none;
61
+ }
62
+ .markdown-body h1:hover .anchor .octicon-link, .markdown-body h2:hover .anchor .octicon-link, .markdown-body h3:hover .anchor .octicon-link, .markdown-body h4:hover .anchor .octicon-link, .markdown-body h5:hover .anchor .octicon-link, .markdown-body h6:hover .anchor .octicon-link {
63
+ display: inline-block;
64
+ }
65
+ .markdown-body h1 tt, .markdown-body h1 code, .markdown-body h2 tt, .markdown-body h2 code, .markdown-body h3 tt, .markdown-body h3 code, .markdown-body h4 tt, .markdown-body h4 code, .markdown-body h5 tt, .markdown-body h5 code, .markdown-body h6 tt, .markdown-body h6 code {
66
+ font-size: inherit;
67
+ }
68
+ .markdown-body h1 {
69
+ border-bottom: 1px solid #eee;
70
+ font-size: 2.25em;
71
+ line-height: 1.2;
72
+ padding-bottom: 0.3em;
73
+ }
74
+ .markdown-body h2 {
75
+ border-bottom: 1px solid #eee;
76
+ font-size: 1.75em;
77
+ line-height: 1.225;
78
+ padding-bottom: 0.3em;
79
+ }
80
+ .markdown-body h3 {
81
+ font-size: 1.5em;
82
+ line-height: 1.43;
83
+ }
84
+ .markdown-body h4 {
85
+ font-size: 1.25em;
86
+ }
87
+ .markdown-body h5 {
88
+ font-size: 1em;
89
+ }
90
+ .markdown-body h6 {
91
+ color: #777;
92
+ font-size: 1em;
93
+ }
94
+ .markdown-body p, .markdown-body blockquote, .markdown-body ul, .markdown-body ol, .markdown-body dl, .markdown-body table, .markdown-body pre {
95
+ margin-bottom: 16px;
96
+ margin-top: 0;
97
+ }
98
+ .markdown-body hr {
99
+ background-color: #e7e7e7;
100
+ border: 0 none;
101
+ height: 4px;
102
+ margin: 16px 0;
103
+ padding: 0;
104
+ }
105
+ .markdown-body ul, .markdown-body ol {
106
+ padding-left: 2em;
107
+ }
108
+ .markdown-body ul.no-list, .markdown-body ol.no-list {
109
+ list-style-type: none;
110
+ padding: 0;
111
+ }
112
+ .markdown-body ul ul, .markdown-body ul ol, .markdown-body ol ol, .markdown-body ol ul {
113
+ margin-bottom: 0;
114
+ margin-top: 0;
115
+ }
116
+ .markdown-body li > p {
117
+ margin-top: 16px;
118
+ }
119
+ .markdown-body dl {
120
+ padding: 0;
121
+ }
122
+ .markdown-body dl dt {
123
+ font-size: 1em;
124
+ font-style: italic;
125
+ font-weight: bold;
126
+ margin-top: 16px;
127
+ padding: 0;
128
+ }
129
+ .markdown-body dl dd {
130
+ margin-bottom: 16px;
131
+ padding: 0 16px;
132
+ }
133
+ .markdown-body blockquote {
134
+ border-left: 4px solid #ddd;
135
+ color: #777;
136
+ padding: 0 15px;
137
+ }
138
+ .markdown-body blockquote > *:first-child {
139
+ margin-top: 0;
140
+ }
141
+ .markdown-body blockquote > *:last-child {
142
+ margin-bottom: 0;
143
+ }
144
+ .markdown-body table {
145
+ display: block;
146
+ overflow: auto;
147
+ width: 100%;
148
+ word-break: keep-all;
149
+ }
150
+ .markdown-body table th {
151
+ font-weight: bold;
152
+ }
153
+ .markdown-body table th, .markdown-body table td {
154
+ border: 1px solid #ddd;
155
+ padding: 6px 13px;
156
+ }
157
+ .markdown-body table tr {
158
+ background-color: #fff;
159
+ border-top: 1px solid #ccc;
160
+ }
161
+ .markdown-body table tr:nth-child(2n) {
162
+ background-color: #f8f8f8;
163
+ }
164
+ .markdown-body img {
165
+ box-sizing: border-box;
166
+ max-width: 100%;
167
+ }
168
+ .markdown-body span.frame {
169
+ display: block;
170
+ overflow: hidden;
171
+ }
172
+ .markdown-body span.frame > span {
173
+ border: 1px solid #ddd;
174
+ display: block;
175
+ float: left;
176
+ margin: 13px 0 0;
177
+ overflow: hidden;
178
+ padding: 7px;
179
+ width: auto;
180
+ }
181
+ .markdown-body span.frame span img {
182
+ display: block;
183
+ float: left;
184
+ }
185
+ .markdown-body span.frame span span {
186
+ clear: both;
187
+ color: #333;
188
+ display: block;
189
+ padding: 5px 0 0;
190
+ }
191
+ .markdown-body span.align-center {
192
+ clear: both;
193
+ display: block;
194
+ overflow: hidden;
195
+ }
196
+ .markdown-body span.align-center > span {
197
+ display: block;
198
+ margin: 13px auto 0;
199
+ overflow: hidden;
200
+ text-align: center;
201
+ }
202
+ .markdown-body span.align-center span img {
203
+ margin: 0 auto;
204
+ text-align: center;
205
+ }
206
+ .markdown-body span.align-right {
207
+ clear: both;
208
+ display: block;
209
+ overflow: hidden;
210
+ }
211
+ .markdown-body span.align-right > span {
212
+ display: block;
213
+ margin: 13px 0 0;
214
+ overflow: hidden;
215
+ text-align: right;
216
+ }
217
+ .markdown-body span.align-right span img {
218
+ margin: 0;
219
+ text-align: right;
220
+ }
221
+ .markdown-body span.float-left {
222
+ display: block;
223
+ float: left;
224
+ margin-right: 13px;
225
+ overflow: hidden;
226
+ }
227
+ .markdown-body span.float-left span {
228
+ margin: 13px 0 0;
229
+ }
230
+ .markdown-body span.float-right {
231
+ display: block;
232
+ float: right;
233
+ margin-left: 13px;
234
+ overflow: hidden;
235
+ }
236
+ .markdown-body span.float-right > span {
237
+ display: block;
238
+ margin: 13px auto 0;
239
+ overflow: hidden;
240
+ text-align: right;
241
+ }
242
+ .markdown-body code, .markdown-body tt {
243
+ background-color: rgba(0, 0, 0, 0.04);
244
+ border-radius: 3px;
245
+ font-size: 85%;
246
+ margin: 0;
247
+ padding: 0.2em 0;
248
+ }
249
+ .markdown-body code:before, .markdown-body code:after, .markdown-body tt:before, .markdown-body tt:after {
250
+ content: " ";
251
+ letter-spacing: -0.2em;
252
+ }
253
+ .markdown-body code br, .markdown-body tt br {
254
+ display: none;
255
+ }
256
+ .markdown-body del code {
257
+ text-decoration: inherit;
258
+ }
259
+ .markdown-body pre > code {
260
+ background: none repeat scroll 0 0 transparent;
261
+ border: 0 none;
262
+ font-size: 100%;
263
+ margin: 0;
264
+ padding: 0;
265
+ white-space: pre;
266
+ word-break: normal;
267
+ }
268
+ .markdown-body .highlight {
269
+ margin-bottom: 16px;
270
+ }
271
+ .markdown-body .highlight pre, .markdown-body pre {
272
+ background-color: #f7f7f7;
273
+ border-radius: 3px;
274
+ font-size: 85%;
275
+ line-height: 1.45;
276
+ overflow: auto;
277
+ padding: 16px;
278
+ }
279
+ .markdown-body .highlight pre {
280
+ margin-bottom: 0;
281
+ word-break: normal;
282
+ }
283
+ .markdown-body pre {
284
+ word-wrap: normal;
285
+ }
286
+ .markdown-body pre code, .markdown-body pre tt {
287
+ background-color: transparent;
288
+ border: 0 none;
289
+ display: inline;
290
+ line-height: inherit;
291
+ margin: 0;
292
+ max-width: initial;
293
+ overflow: initial;
294
+ padding: 0;
295
+ word-wrap: normal;
296
+ }
297
+ .markdown-body pre code:before, .markdown-body pre code:after, .markdown-body pre tt:before, .markdown-body pre tt:after {
298
+ content: normal;
299
+ }
@@ -0,0 +1,5 @@
1
+ require 'rdiscount'
2
+ module ChangeLog
3
+ class ApplicationController < ActionController::Base
4
+ end
5
+ end
@@ -0,0 +1,17 @@
1
+ module ChangeLog
2
+ class BaseController < ::ApplicationController
3
+ layout ChangeLog.config.layout
4
+
5
+ def index
6
+ @items = _model.fetch(params)
7
+ end
8
+
9
+ def _model
10
+ if ChangeLog.config.orm == 'activerecord'
11
+ ChangeLog::ActiverecordModel
12
+ else
13
+ ChangeLog::MongoidModel
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,8 @@
1
+ require 'kramdown'
2
+ module ChangeLog
3
+ module ApplicationHelper
4
+ def md(string)
5
+ Kramdown::Document.new(string).to_html.html_safe
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,12 @@
1
+ module ChangeLog
2
+ class ActiverecordModel < ActiveRecord::Base
3
+
4
+ def self.fetch(options)
5
+ self.order('time desc')
6
+ end
7
+
8
+ def self.last_release
9
+ last
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,20 @@
1
+ module ChangeLog
2
+ class MongoidModel
3
+ include Mongoid::Document
4
+ include Mongoid::Timestamps
5
+
6
+ field :version, type: String
7
+ field :author, type: String
8
+ field :message, type: String
9
+ field :time, type: DateTime
10
+ field :tags
11
+
12
+ def self.fetch(option)
13
+ all.desc('time')
14
+ end
15
+
16
+ def self.last_release
17
+ last
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,5 @@
1
+ <% @items.each do |item| %>
2
+ <h2> <%= item.version %> {<%= item.time %>}</h2>
3
+ <%= md item.message %>
4
+ <br/>
5
+ <% end %>
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>ChangeLog</title>
5
+ <%= stylesheet_link_tag "change_log/application", :media => "all" %>
6
+ <%= javascript_include_tag "change_log/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+ <div class="markdown-body">
11
+ <%= yield %>
12
+ </div>
13
+ </body>
14
+ </html>
data/config/routes.rb ADDED
@@ -0,0 +1,3 @@
1
+ ChangeLog::Engine.routes.draw do
2
+ root :to => 'base#index'
3
+ end
@@ -0,0 +1,31 @@
1
+ require 'active_support/core_ext/class/attribute_accessors'
2
+
3
+ module ChangeLog
4
+ module Config
5
+
6
+ class << self
7
+ # Table prefix to avoid collision
8
+ attr_accessor :table_prefix
9
+
10
+ #layout name default applocation
11
+ attr_accessor :layout
12
+
13
+ #commit message prefix
14
+ attr_accessor :commit_prefix
15
+
16
+ attr_accessor :orm
17
+
18
+ attr_accessor :tag_prefix
19
+
20
+ def reset
21
+ @layout = 'change_log/application'
22
+ @table_prefix = nil
23
+ @commit_prefix = '~~~'
24
+ @tag_prefix = '~~'
25
+ end
26
+ end
27
+
28
+ # Set default values for configuration options on load
29
+ self.reset
30
+ end
31
+ end
@@ -0,0 +1,10 @@
1
+ module ChangeLog
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace ChangeLog
4
+ initializer 'change_log.action_controller' do |app|
5
+ ActiveSupport.on_load :action_controller do
6
+ helper ChangeLog::ApplicationHelper
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,14 @@
1
+ require 'rdiscount'
2
+
3
+ module MarkdownHandler
4
+ def self.erb
5
+ @erb ||= ActionView::Template.registered_template_handler(:erb)
6
+ end
7
+
8
+ def self.call(template)
9
+ compiled_source = erb.call(template)
10
+ "RDiscount.new(begin;#{compiled_source};end).to_html"
11
+ end
12
+ end
13
+
14
+ ActionView::Template.register_template_handler :md, MarkdownHandler
@@ -0,0 +1,3 @@
1
+ module ChangeLog
2
+ VERSION = "0.0.1"
3
+ end
data/lib/change_log.rb ADDED
@@ -0,0 +1,13 @@
1
+ require "change_log/config"
2
+ require "change_log/engine"
3
+
4
+ module ChangeLog
5
+ # Setup ChangeLog
6
+ def self.config(&block)
7
+ if block_given?
8
+ block.call(ChangeLog::Config)
9
+ else
10
+ ChangeLog::Config
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,57 @@
1
+ require 'rails/generators'
2
+ require File.expand_path('../utils', __FILE__)
3
+
4
+ # http://guides.rubyonrails.org/generators.html
5
+ # http://rdoc.info/github/wycats/thor/master/Thor/Actions.html
6
+ # keep generator idempotent, thanks
7
+ # Thanks to https://github.com/sferik/rails_admin !
8
+
9
+ module ChangeLog
10
+ class InstallGenerator < Rails::Generators::Base
11
+
12
+ source_root File.expand_path("../templates", __FILE__)
13
+ include Rails::Generators::Migration
14
+ include Generators::Utils::InstanceMethods
15
+ extend Generators::Utils::ClassMethods
16
+
17
+ argument :_namespace, :type => :string, :required => false, :desc => "ChangeLog url namespace"
18
+ argument :_table_prefix, :type => :string, :required => false, :desc => "Prefix for change_log tables "
19
+ argument :_orm, :type => :string, :required => false, :desc => "ORM <activerecord or mongoid>"
20
+ desc "ChangeLog installation generator"
21
+
22
+ def install
23
+ routes = File.open(Rails.root.join("config/routes.rb")).try :read
24
+ initializer = (File.open(Rails.root.join("config/initializers/change_log.rb")) rescue nil).try :read
25
+
26
+ display "Hello, ChangeLog installer will help you sets things up!", :black
27
+ unless initializer
28
+ #install_generator = ask_boolean("Do you want to install the optional configuration file (to change mappings, locales dump location etc..) ?")
29
+ @orm = multiple_choice "Please select orm", [["ActiveRecord", "activerecord"], ["Mongoid", "mongoid"]]
30
+
31
+ _table = @orm == 'mongoid' ? 'collection' : 'table'
32
+ @table_prefix = ask_for("Do you want to add #{_table} prefix?", nil, table_prefix)
33
+ template "initializer.erb", "config/initializers/change_log.rb"
34
+ else
35
+ display "You already have a config file. You're updating, heh? I'm generating a new 'change_log.rb.example' that you can review."
36
+ template "initializer.erb", "config/initializers/change_log.rb.example"
37
+ end
38
+
39
+ if @orm == 'activerecord'
40
+ display "Adding a migration..."
41
+ migration_template 'migration.rb', 'db/migrate/create_change_log_tables.rb' #rescue display $!.message
42
+ end
43
+
44
+ namespace = ask_for("Where do you want to mount change_log?", "change_log", _namespace)
45
+ gsub_file "config/routes.rb", /mount ChangeLog::Engine => \'\/.+\', :as => \'change_log\' if defined\? ChangeLog/, ''
46
+ gsub_file "config/routes.rb", /mount ChangeLog::Engine => \'\/.+\', :as => \'change_log\'/, ''
47
+ gsub_file "config/routes.rb", /mount ChangeLog::Engine => \'\/.+\'/, ''
48
+ route("mount ChangeLog::Engine => '/#{namespace}', :as => 'change_log' if defined? ChangeLog")
49
+
50
+ display "Job's done: migrate,now modify initilizer[optional], start your server and visit '/#{namespace}'!", :blue
51
+ end
52
+
53
+ def table_prefix
54
+ @table_prefix
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,34 @@
1
+ # encoding: utf-8
2
+
3
+ # ChangeLog config file. Generated on <%= DateTime.now.to_s(:long) %>
4
+ # See github.com/amuntasim/change_log for more informations
5
+
6
+ #ChangeLog::ApplicationController.authenticator = proc {
7
+ # authenticate_or_request_with_http_basic('ChangeLog') do |user_name, password|
8
+ # user_name == 'change_log' && password == 'password'
9
+ # end
10
+ #}
11
+
12
+ ChangeLog.config do |config|
13
+ <% if table_prefix.present? -%>
14
+ config.table_prefix = '<%= table_prefix %>'
15
+ <% else -%>
16
+ #config.table_prefix = ''
17
+ <% end -%>
18
+
19
+ config.orm = '<%= @orm %>'
20
+
21
+ #config.layout = 'change_log/application'
22
+
23
+ #config.commit_prefix = '~~~'
24
+
25
+ #config.tag_prefix = '~~'
26
+ end if defined? ChangeLog
27
+
28
+ <% if @table_prefix.present? %>
29
+ <% if @orm == 'mongoid' -%>
30
+ ChangeLog::MongoidModel.store_in collection: :'<%= [@table_prefix, 'change_logs'].compact.join('_') %>'
31
+ <% else %>
32
+ ChangeLog::ActiverecordModel.table_name = '<%= [@table_prefix, 'change_logs'].compact.join('_') %>'
33
+ <% end -%>
34
+ <% end %>
@@ -0,0 +1,20 @@
1
+ class CreateTolkTables < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :<%= [table_prefix, 'change_logs'].compact.join('_') %> do |t|
4
+ t.string :version, limit: 20
5
+ t.datetime :time
6
+ t.string :message, limit: 1000
7
+ t.string :author, limit: 50
8
+ t.datetime :created_at
9
+ t.datetime :updated_at
10
+ end
11
+
12
+ add_index :<%= [table_prefix, 'change_logs'].compact.join('_') %>, :category
13
+
14
+ end
15
+
16
+ def self.down
17
+ drop_table :<%=[table_prefix, 'change_logs'].compact.join('_') %>
18
+ end
19
+
20
+ end