magick_pen 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +155 -0
- data/Rakefile +18 -0
- data/app/controllers/magick_pen/snippets_controller.rb +73 -0
- data/app/models/magick_pen/snippet.rb +49 -0
- data/app/views/magick_pen/_config.html.erb +133 -0
- data/app/views/magick_pen/_load.html.erb +7 -0
- data/config/locales/en.yml +10 -0
- data/config/locales/ja.yml +10 -0
- data/config/routes.rb +8 -0
- data/db/migrate/20210430221213_create_snippets_magick_pen.rb +15 -0
- data/lib/generators/magick_pen/install_generator.rb +42 -0
- data/lib/magick_pen.rb +8 -0
- data/lib/magick_pen/engine.rb +4 -0
- data/lib/magick_pen/version.rb +3 -0
- data/lib/tasks/magick_pen_tasks.rake +4 -0
- metadata +96 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5e8a29ab1a7402988822d6e68d017351539e316a76fe77470768e158e868e9fe
|
4
|
+
data.tar.gz: fa20ab13727f40e69dc9e63d257a35f0935ea5a68ebc1b40ac040c2f4d861045
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0e6d2318e7c958864f3dca9c077e627afd712397b3398977597cdf14741ee251df796b264a558ce106e6fed4a97d0e58c62ae0b93aa764ed37eaf7f1f7685268
|
7
|
+
data.tar.gz: d100c281eb352c4cf0a8cbf4e2add3851bab1b4bb6dce1b993bf5e3440ce4c8d85f846b14e9ad0adc9eca1447c1b515c148bba8c4c8d933d0e779447ac97ca37
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2021 Kazuo Matsunaga
|
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.md
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
# Magick Pen
|
2
|
+
|
3
|
+
Magick Penは、Railsプロジェクトに組み込んで利用できるGemのプラグインです。
|
4
|
+
テンプレートファイル(.erbファイル)の任意の部分を <vue-magick-pen> 〜 </vue-magick-pen> で囲むだけで、Webページから直接変更ができるようになります。
|
5
|
+
|
6
|
+
また、変更内容を履歴管理していますので、過去の内容に戻すことも簡単です。
|
7
|
+
|
8
|
+
<img src="https://user-images.githubusercontent.com/2704723/117098232-dbe10400-ada8-11eb-8d50-e8dd87365a4b.gif"/>
|
9
|
+
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
あなたのRailsプロジェクトの Gemfiie に magick_penを追加します。
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'magick_pen'
|
17
|
+
```
|
18
|
+
|
19
|
+
bundleを更新して、Magick Penのインストールを実行します。
|
20
|
+
|
21
|
+
```bash
|
22
|
+
$ bundle
|
23
|
+
$ rails g magick_pen:install
|
24
|
+
```
|
25
|
+
|
26
|
+
## 準備
|
27
|
+
|
28
|
+
ここでは、Rails Sprocketsを使ってアセットコンパイルして利用する方法を説明します。
|
29
|
+
|
30
|
+
### app/assets/stylesheets/application.css
|
31
|
+
|
32
|
+
nodeモジュールからmagick penのcssを読み込みます。
|
33
|
+
|
34
|
+
```css
|
35
|
+
/*
|
36
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
37
|
+
* listed below.
|
38
|
+
*
|
39
|
+
|
40
|
+
*= require "vue-magick-pen/dist/vue-magick-pen"
|
41
|
+
*/
|
42
|
+
```
|
43
|
+
|
44
|
+
### app/assets/javascript/application.js
|
45
|
+
|
46
|
+
nodeモジュールからvue.jsと magick penのVueコンポーネントを読み込みます。
|
47
|
+
|
48
|
+
|
49
|
+
```javascript
|
50
|
+
/*
|
51
|
+
|
52
|
+
//= require vue/dist/vue
|
53
|
+
//= require vue-magick-pen/dist/vue-magick-pen.umd
|
54
|
+
|
55
|
+
*/
|
56
|
+
```
|
57
|
+
|
58
|
+
|
59
|
+
### app/views/layouts/application.html.erb
|
60
|
+
|
61
|
+
```html
|
62
|
+
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
|
63
|
+
<%= javascript_include_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
|
64
|
+
```
|
65
|
+
|
66
|
+
layouts/application.html.erb から application.jsと application.cssを読み込めば準備は完了です。
|
67
|
+
|
68
|
+
# ページを作成する
|
69
|
+
|
70
|
+
### app/views/xxxxx/index.html.erb
|
71
|
+
|
72
|
+
任意のコントローラー、アクションを作成し、テンプレートファイルをマークアップします。
|
73
|
+
|
74
|
+
```html
|
75
|
+
<div id="magick-pen">
|
76
|
+
<h1>Title</h1>
|
77
|
+
<div>
|
78
|
+
<magick-pen pen-key="snippet-1">
|
79
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
|
80
|
+
Mauris pellentesque malesuada convallis.
|
81
|
+
Quisque condimentum ac odio ut congue. Integer ultrices a erat sed hendrerit.
|
82
|
+
</magick-pen>
|
83
|
+
</div>
|
84
|
+
|
85
|
+
<div>
|
86
|
+
<magick-pen pen-key="snippet-2">
|
87
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
|
88
|
+
Mauris pellentesque malesuada convallis.
|
89
|
+
Quisque condimentum ac odio ut congue. Integer ultrices a erat sed hendrerit.
|
90
|
+
</magick-pen>
|
91
|
+
</div>
|
92
|
+
</div>
|
93
|
+
|
94
|
+
<%= render partial: 'magick_pen/load', locals: { editable: true } %>
|
95
|
+
|
96
|
+
```
|
97
|
+
|
98
|
+
マークアップのルールは以下の通りです。
|
99
|
+
- id="magick-pen" で 囲った部分が有効になります。この範囲内であれば、何か所でも Magick Pen を埋め込めます。
|
100
|
+
- magick penを埋め込みたい部分を <vue-magick-pen> 〜 </vue-magick-pen> で囲みます。
|
101
|
+
- この時、キーとなる文字列を pen-key属性に設定して下さい。
|
102
|
+
- pen-key は (コントローラー名+アクション名) のスコープでユニークとなるようにして下さい。別コントローラー、別アクションであれば、同じpen-keyでも別物として扱われます。
|
103
|
+
- ページフッターやサイドバーなどサイト全体で共通に扱いたい部分でMagick Penを埋め込みたい場合は、pen-keyにプレフィックス 'g-' を付けて下さい (例:g-snippet-1)。
|
104
|
+
- ファイルの最後に <%= render partial: 'magick_pen/load', locals: { editable: true } %> を記述します。
|
105
|
+
- editableが falseであれば、何もなかったように普通にページが表示されます。trueであれば編集可能になります。ユーザー権限などに応じてeditableの値をコントロールして下さい。
|
106
|
+
- id="magick-pen" の値を変更したい場合は、'magick_pen/load' の locals に、elementを渡すことができます。
|
107
|
+
|
108
|
+
```html
|
109
|
+
<div id="page">
|
110
|
+
:
|
111
|
+
:
|
112
|
+
:
|
113
|
+
|
114
|
+
</div>
|
115
|
+
<%= render partial: 'magick_pen/load', locals: { editable: true, element: '#page" } %>
|
116
|
+
```
|
117
|
+
|
118
|
+
Magick Penは多言語対応になっていますので、ボタン名に日本語が表示されない場合は、config/application.rbに以下の設定をします。
|
119
|
+
|
120
|
+
```ruby
|
121
|
+
class Application < Rails::Application
|
122
|
+
:
|
123
|
+
:
|
124
|
+
I18n.available_locales = %i(ja en)
|
125
|
+
I18n.enforce_available_locales = true
|
126
|
+
I18n.default_locale = :ja
|
127
|
+
end
|
128
|
+
```
|
129
|
+
|
130
|
+
|
131
|
+
|
132
|
+
# デザインの適用
|
133
|
+
|
134
|
+
FontAwesome 5 を導入することをお奨めします。FontAwesomeが利用できる環境であればそのままボタン等にアイコンが表示されます。
|
135
|
+
|
136
|
+
Bootstrap 4、または、Bulma を適用した場合は、各CSSフレームワークのデザインに準じて表示されます。独自デザインを適用する場合は、CSSの調整が必要になります。
|
137
|
+
|
138
|
+
gemバンドル内の magick_pen/app/models/magick_pen/snippet.rb を プロジェクトにコピーして適宜変更をして下さい。snippet.rbには、
|
139
|
+
Magick Pen内で使用するボタンのクラス名やラベル名、アイコンのクラス名が定義されています。
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
# サンプルプロジェクト
|
144
|
+
|
145
|
+
[ こちら ]( https://github.com/kazuomatz/magick_pen_demo )にサンプルのRailsプロジェクトがあります。
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
# 動作環境
|
150
|
+
- Ruby 2.6 〜 3.0
|
151
|
+
- Rails 6.0 / 6.1
|
152
|
+
|
153
|
+
|
154
|
+
## License
|
155
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require "bundler/setup"
|
2
|
+
|
3
|
+
APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
|
4
|
+
load "rails/tasks/engine.rake"
|
5
|
+
|
6
|
+
load "rails/tasks/statistics.rake"
|
7
|
+
|
8
|
+
require "bundler/gem_tasks"
|
9
|
+
|
10
|
+
require "rake/testtask"
|
11
|
+
|
12
|
+
Rake::TestTask.new(:test) do |t|
|
13
|
+
t.libs << 'test'
|
14
|
+
t.pattern = 'test/**/*_test.rb'
|
15
|
+
t.verbose = false
|
16
|
+
end
|
17
|
+
|
18
|
+
task default: :test
|
@@ -0,0 +1,73 @@
|
|
1
|
+
class MagickPen::SnippetsController < ApplicationController
|
2
|
+
protect_from_forgery
|
3
|
+
|
4
|
+
def update
|
5
|
+
begin
|
6
|
+
snippet = find_snippet(permitted_attr)
|
7
|
+
if snippet.nil?
|
8
|
+
snippet = MagickPen::Snippet.create!(permitted_attr)
|
9
|
+
else
|
10
|
+
snippet.update!(permitted_attr)
|
11
|
+
end
|
12
|
+
render json: {
|
13
|
+
status: 200,
|
14
|
+
snippet: {
|
15
|
+
pen_key: snippet.pen_key,
|
16
|
+
id: snippet.id,
|
17
|
+
versions: (snippet.versions.order('id desc').map { |v| (v.event == "create" || v.event == "update") ? { id:v.id, date: v.created_at } : nil }).compact
|
18
|
+
}
|
19
|
+
}
|
20
|
+
rescue => e
|
21
|
+
render json: { status: 500, message: e.message }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def version
|
26
|
+
snippet = find_snippet(params)
|
27
|
+
if snippet.nil?
|
28
|
+
render json: { status: 404 }
|
29
|
+
return
|
30
|
+
end
|
31
|
+
if params[:version_id].to_i == 0
|
32
|
+
content = snippet.content
|
33
|
+
render json: { status: 200, snippet: {pen_key: snippet.pen_key, id: snippet.id, content: content} }
|
34
|
+
else
|
35
|
+
version = snippet.versions.where(id: params[:version_id]).first
|
36
|
+
if version.present?
|
37
|
+
if version.event == 'update'
|
38
|
+
snippet = version.reify
|
39
|
+
content = snippet.content
|
40
|
+
else
|
41
|
+
content = snippet.original_content
|
42
|
+
end
|
43
|
+
render json: { status: 200, snippet: {pen_key: snippet.pen_key, id: snippet.id, content: content} }
|
44
|
+
else
|
45
|
+
render json: { status: 404 }
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def permitted_attr
|
53
|
+
if @_permitted_attr
|
54
|
+
@_permitted_attr
|
55
|
+
else
|
56
|
+
@_permitted_attr = params.require('magick_pen_snippet').permit(:pen_key, :action_name, :controller_name, :is_global, :content, :original_content)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def find_snippet(snippet_pram)
|
61
|
+
if snippet_pram.nil?
|
62
|
+
snippet_pram = params
|
63
|
+
end
|
64
|
+
snippet = MagickPen::Snippet.where(pen_key: snippet_pram[:pen_key])
|
65
|
+
if snippet_pram[:is_global].blank? || snippet_pram[:is_global].downcase == 'false'
|
66
|
+
snippet = snippet.where(controller_name: snippet_pram[:controller_name], action_name: snippet_pram[:action_name])
|
67
|
+
else
|
68
|
+
snippet = snippet.where(is_global: true)
|
69
|
+
end
|
70
|
+
snippet.first
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
class MagickPen::Snippet < ApplicationRecord
|
2
|
+
|
3
|
+
has_paper_trail on: [:create, :update]
|
4
|
+
validates :pen_key, presence: true
|
5
|
+
validates_uniqueness_of :pen_key, conditions: -> { where(is_global: true) }
|
6
|
+
validates :action_name, presence: true, if: -> { is_global == false }
|
7
|
+
validates :controller_name, presence: true, if: -> { is_global == false }
|
8
|
+
validates_uniqueness_of :pen_key, scope:[ :action_name, :controller_name ], conditions: -> { where(is_global: false) }
|
9
|
+
validates :content, presence: true
|
10
|
+
validates :original_content, presence: true
|
11
|
+
|
12
|
+
class << self
|
13
|
+
def config
|
14
|
+
{
|
15
|
+
"date_format": "YYYY/MM/DD HH:mm",
|
16
|
+
"select": {
|
17
|
+
"class": "magick-pen-select",
|
18
|
+
"label": {
|
19
|
+
"version": I18n.t('magick_pen.version'),
|
20
|
+
"original": I18n.t('magick_pen.original'),
|
21
|
+
"current": I18n.t('magick_pen.current'),
|
22
|
+
}
|
23
|
+
},
|
24
|
+
"buttons": {
|
25
|
+
"edit": {
|
26
|
+
"class": "btn btn-primary btn-sm button is-primary is-small",
|
27
|
+
"icon": "fas fa-edit",
|
28
|
+
"label": I18n.t('magick_pen.buttons.edit')
|
29
|
+
},
|
30
|
+
"update": {
|
31
|
+
"class": "btn btn-primary btn-sm button is-primary is-small",
|
32
|
+
"icon": "fas fa-upload",
|
33
|
+
"label":I18n.t('magick_pen.buttons.update')
|
34
|
+
},
|
35
|
+
"cancel": {
|
36
|
+
"class": "btn btn-secondary btn-sm button is-light is-small",
|
37
|
+
"icon": "fas fa-times",
|
38
|
+
"label": I18n.t('magick_pen.buttons.cancel')
|
39
|
+
},
|
40
|
+
"preview": {
|
41
|
+
"class": "btn btn-primary btn-sm button is-primary is-small",
|
42
|
+
"icon": "fas fa-eye",
|
43
|
+
"label": I18n.t('magick_pen.buttons.preview')
|
44
|
+
}
|
45
|
+
}
|
46
|
+
}
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
<%
|
2
|
+
snippets = MagickPen::Snippet.includes(:versions).where(
|
3
|
+
["(controller_name = ? and action_name = ?) || is_global = true", params[:controller], params[:action]]
|
4
|
+
)
|
5
|
+
contents = snippets.map {|snippet|
|
6
|
+
{
|
7
|
+
id: snippet.id,
|
8
|
+
pen_key: snippet.pen_key,
|
9
|
+
content: snippet.content,
|
10
|
+
versions: snippet.versions.map do |version|
|
11
|
+
(version.event == "create" || version.event == "update") ? { id: version.id, date: version.created_at} : nil
|
12
|
+
end.compact
|
13
|
+
}
|
14
|
+
}
|
15
|
+
%>
|
16
|
+
|
17
|
+
<script>
|
18
|
+
if (!Object.assign) {
|
19
|
+
Object.defineProperty(Object, 'assign', {
|
20
|
+
enumerable: false,
|
21
|
+
configurable: true,
|
22
|
+
writable: true,
|
23
|
+
value: function(target) {
|
24
|
+
'use strict';
|
25
|
+
if (target === undefined || target === null) {
|
26
|
+
throw new TypeError('Cannot convert first argument to object');
|
27
|
+
}
|
28
|
+
|
29
|
+
var to = Object(target);
|
30
|
+
for (var i = 1; i < arguments.length; i++) {
|
31
|
+
var nextSource = arguments[i];
|
32
|
+
if (nextSource === undefined || nextSource === null) {
|
33
|
+
continue;
|
34
|
+
}
|
35
|
+
nextSource = Object(nextSource);
|
36
|
+
|
37
|
+
var keysArray = Object.keys(Object(nextSource));
|
38
|
+
for (var nextIndex = 0, len = keysArray.length; nextIndex < len; nextIndex++) {
|
39
|
+
var nextKey = keysArray[nextIndex];
|
40
|
+
var desc = Object.getOwnPropertyDescriptor(nextSource, nextKey);
|
41
|
+
if (desc !== undefined && desc.enumerable) {
|
42
|
+
to[nextKey] = nextSource[nextKey];
|
43
|
+
}
|
44
|
+
}
|
45
|
+
}
|
46
|
+
return to;
|
47
|
+
}
|
48
|
+
});
|
49
|
+
}
|
50
|
+
var magickPenConfig = Object.assign ({
|
51
|
+
controller: '<%= params[:controller] %>',
|
52
|
+
action: '<%= params[:action] %>',
|
53
|
+
snippets: <%= raw contents.to_json %>,
|
54
|
+
editable: <%= defined?(editable) ? editable : false %>,
|
55
|
+
updateSnippet: function (key, content, originalContent, completed) {
|
56
|
+
var xhr = new XMLHttpRequest();
|
57
|
+
xhr.open('POST', '<%= magick_pen_snippet_path %>', true)
|
58
|
+
xhr.onreadystatechange = function () {
|
59
|
+
if (xhr.readyState !== 4 || xhr.status !== 200) {
|
60
|
+
}
|
61
|
+
else {
|
62
|
+
var data = JSON.parse(xhr.responseText)
|
63
|
+
if (data.status === 200) {
|
64
|
+
var b = false
|
65
|
+
for( var i = 0 ; i < this.snippets.length ; i ++ ) {
|
66
|
+
if (this.snippets[i].id === data.snippet.id) {
|
67
|
+
this.snippets[i].versions = data.snippet.versions
|
68
|
+
b = true
|
69
|
+
if(completed) {
|
70
|
+
completed(data.snippet)
|
71
|
+
}
|
72
|
+
break
|
73
|
+
}
|
74
|
+
}
|
75
|
+
if (!b) {
|
76
|
+
this.snippets.push(data.snippet)
|
77
|
+
if(completed) {
|
78
|
+
completed(data.snippet)
|
79
|
+
}
|
80
|
+
}
|
81
|
+
}
|
82
|
+
}
|
83
|
+
}.bind(this);
|
84
|
+
|
85
|
+
var data = new FormData()
|
86
|
+
data.append('authenticity_token', '<%= magick_pen_snippet_path %>')
|
87
|
+
data.append('magick_pen_snippet[pen_key]', key)
|
88
|
+
data.append('magick_pen_snippet[content]', content)
|
89
|
+
if (originalContent) {
|
90
|
+
data.append('magick_pen_snippet[original_content]', originalContent)
|
91
|
+
}
|
92
|
+
if (key.slice(0,2) === 'g-') {
|
93
|
+
data.append('magick_pen_snippet[is_global]',true)
|
94
|
+
}
|
95
|
+
else {
|
96
|
+
data.append('magick_pen_snippet[action_name]',this.action)
|
97
|
+
data.append('magick_pen_snippet[controller_name]',this.controller)
|
98
|
+
data.append('magick_pen_snippet[is_global]',false)
|
99
|
+
}
|
100
|
+
xhr.send(data);
|
101
|
+
},
|
102
|
+
|
103
|
+
getVersion: function (key, versionId, completed) {
|
104
|
+
var xhr = new XMLHttpRequest();
|
105
|
+
var url = "<%= magick_pen_snippet_version_path %>"
|
106
|
+
url += "?pen_key=" + key
|
107
|
+
url += "&version_id=" + versionId
|
108
|
+
if (key.slice(0,2) === 'g-') {
|
109
|
+
url += "&is_global=true"
|
110
|
+
}
|
111
|
+
else {
|
112
|
+
url += "&action_name=" + this.action
|
113
|
+
url += "&controller_name=" + this.controller
|
114
|
+
url += "&is_global=false"
|
115
|
+
}
|
116
|
+
xhr.open('GET', url, true);
|
117
|
+
xhr.onreadystatechange = function () {
|
118
|
+
if (xhr.readyState !== 4 || xhr.status !== 200) {
|
119
|
+
|
120
|
+
}
|
121
|
+
else {
|
122
|
+
var data = JSON.parse(xhr.responseText)
|
123
|
+
if (data.status === 200) {
|
124
|
+
if (completed) {
|
125
|
+
completed(data.snippet)
|
126
|
+
}
|
127
|
+
}
|
128
|
+
}
|
129
|
+
}.bind(this)
|
130
|
+
xhr.send()
|
131
|
+
}
|
132
|
+
}, <%= raw MagickPen::Snippet.config.to_json %> )
|
133
|
+
</script>
|
data/config/routes.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
class CreateSnippetsMagickPen < ActiveRecord::Migration[6.0]
|
2
|
+
def change
|
3
|
+
create_table :magick_pen_snippets do |t|
|
4
|
+
t.string :pen_key, comment: 'key'
|
5
|
+
t.string :controller_name
|
6
|
+
t.string :action_name
|
7
|
+
t.boolean :is_global, default: false, comment: 'for Global Snippet'
|
8
|
+
t.text :content, comment: 'content html / limit: 4294967295 If necessary'
|
9
|
+
t.text :original_content, comment: 'Original content html / limit: 4294967295 If necessary'
|
10
|
+
t.timestamps
|
11
|
+
end
|
12
|
+
add_index :magick_pen_snippets, :pen_key
|
13
|
+
add_index :magick_pen_snippets, [:pen_key, :controller_name, :action_name], name: 'key_controller_action'
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require "rails/generators"
|
2
|
+
|
3
|
+
module MagickPen
|
4
|
+
class InstallGenerator < Rails::Generators::Base
|
5
|
+
class_option "with-migrate", type: :boolean
|
6
|
+
|
7
|
+
def start
|
8
|
+
puts "Start installing Magick Pen..."
|
9
|
+
puts "*" * 80 + "\n"
|
10
|
+
end
|
11
|
+
|
12
|
+
def check_paper_trail
|
13
|
+
puts "Paper Trail Install...."
|
14
|
+
Dir.chdir(Rails.root) do
|
15
|
+
`bundle exec rails generate paper_trail:install`
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def install_migrations
|
20
|
+
puts "Copying over Magick Pen migrations..."
|
21
|
+
Dir.chdir(Rails.root) do
|
22
|
+
`bundle exec rake magick_pen_engine:install:migrations`
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def run_migrations
|
27
|
+
return unless options["with-migrate"]
|
28
|
+
puts "Running rake db:migrate"
|
29
|
+
`bundle exec rake db:migrate`
|
30
|
+
end
|
31
|
+
|
32
|
+
def install_npm
|
33
|
+
puts "Running npm install vue_magick_pen"
|
34
|
+
`npm install vue-magick-pen`
|
35
|
+
end
|
36
|
+
|
37
|
+
def finished
|
38
|
+
puts "\n" + ("*" * 80)
|
39
|
+
puts "Done! Magick Pen has been successfully installed."
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/magick_pen.rb
ADDED
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: magick_pen
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kazuo Matsunaga
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-05-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '6.0'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '6.2'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '6.0'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '6.2'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: paper_trail
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
description: The part of the erb file enclosed in <vue-magick-pen> tags can be edited.
|
48
|
+
email:
|
49
|
+
- kazuomatz@lifecode.jp
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- MIT-LICENSE
|
55
|
+
- README.md
|
56
|
+
- Rakefile
|
57
|
+
- app/controllers/magick_pen/snippets_controller.rb
|
58
|
+
- app/models/magick_pen/snippet.rb
|
59
|
+
- app/views/magick_pen/_config.html.erb
|
60
|
+
- app/views/magick_pen/_load.html.erb
|
61
|
+
- config/locales/en.yml
|
62
|
+
- config/locales/ja.yml
|
63
|
+
- config/routes.rb
|
64
|
+
- db/migrate/20210430221213_create_snippets_magick_pen.rb
|
65
|
+
- lib/generators/magick_pen/install_generator.rb
|
66
|
+
- lib/magick_pen.rb
|
67
|
+
- lib/magick_pen/engine.rb
|
68
|
+
- lib/magick_pen/version.rb
|
69
|
+
- lib/tasks/magick_pen_tasks.rake
|
70
|
+
homepage: https://github.com/kazuomatz/magick_pen
|
71
|
+
licenses:
|
72
|
+
- MIT
|
73
|
+
metadata:
|
74
|
+
homepage_uri: https://github.com/kazuomatz/magick_pen
|
75
|
+
source_code_uri: https://github.com/kazuomatz/magick_pen
|
76
|
+
changelog_uri: https://github.com/kazuomatz/magick_pen
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubygems_version: 3.0.3
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: Plug-in that allows you to edit a Web page to direct.
|
96
|
+
test_files: []
|