Skip to content

Commit

Permalink
Merge pull request #30 from onozaty/support-redmine4
Browse files Browse the repository at this point in the history
Support redmine4
  • Loading branch information
onozaty authored Dec 10, 2018
2 parents 13cc455 + 7b41b60 commit f4bf47b
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 34 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gem 'activerecord-compatible_legacy_migration'
14 changes: 9 additions & 5 deletions README.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@

Redmineのプラグインディレクトリに、このリポジトリを`view_customize`としてクローンします。

cd {RAILS_ROOT}/plugins
git clone https://github.com/onozaty/redmine-view-customize.git view_customize
cd ../
bundle exec rake redmine:plugins:migrate RAILS_ENV=production
```
cd {RAILS_ROOT}/plugins
git clone https://github.com/onozaty/redmine-view-customize.git view_customize
cd ../
bundle install --without development test
bundle exec rake redmine:plugins:migrate RAILS_ENV=production
```

**注意: ディレクトリ名は`view_customize`とする必要があります。ディレクトリ名が異なると、プラグインの実行に失敗します。**

Expand Down Expand Up @@ -124,7 +127,8 @@ ViewCustomize = {

## サポートバージョン

* Redmine 2.0.x 以降
* 最新バージョン : Redmine 3.1.x 以降
* 1.2.2 : Redmine 2.0.x から 3.4.x

## ライセンス

Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Install the plugin in your Redmine plugins directory, clone this repository as `
cd {RAILS_ROOT}/plugins
git clone https://github.com/onozaty/redmine-view-customize.git view_customize
cd ../
bundle install --without development test
bundle exec rake redmine:plugins:migrate RAILS_ENV=production
```

Expand Down Expand Up @@ -130,9 +131,10 @@ For example, to access the user's API key is `ViewCustomize.context.user.apiKey`

* [onozaty/redmine\-view\-customize\-scripts: Script list for "Redmine View Customize Plugin"](https://github.com/onozaty/redmine-view-customize-scripts)

## Redmine 2.0.x or later
## Supported versions

* Redmine 2.0.x or later
* Current version : Redmine 3.1.x or later
* 1.2.2 : Redmine 2.0.x - 3.4.x

## License

Expand Down
12 changes: 8 additions & 4 deletions app/controllers/view_customizes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ class ViewCustomizesController < ApplicationController

layout 'admin'

before_filter :require_admin
before_filter :find_view_customize, :except => [:index, :new, :create]
before_action :require_admin
before_action :find_view_customize, :except => [:index, :new, :create]

helper :sort
include SortHelper
Expand All @@ -20,7 +20,7 @@ def new
end

def create
@view_customize = ViewCustomize.new(params[:view_customize])
@view_customize = ViewCustomize.new(view_customize_params)

if @view_customize.save
flash[:notice] = l(:notice_successful_create)
Expand All @@ -37,7 +37,7 @@ def edit
end

def update
@view_customize.attributes = params[:view_customize]
@view_customize.attributes = view_customize_params
if @view_customize.save
flash[:notice] = l(:notice_successful_update)
redirect_to view_customize_path(@view_customize.id)
Expand All @@ -61,4 +61,8 @@ def find_view_customize
render_404 unless @view_customize
end

def view_customize_params
params.require(:view_customize)
.permit(:path_pattern, :customize_type, :code, :is_enabled, :is_private, :insertion_position, :comments)
end
end
3 changes: 2 additions & 1 deletion app/helpers/view_customizes_helper.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
module ViewCustomizesHelper
def highlight_by_language(code, language)
code.gsub!(/(\r\n|\r|\n)/, "\n")
("<pre><code class=\"#{language} syntaxhl\">" +
CodeRay.scan(code, language).html(:wrap => :span) +
Redmine::SyntaxHighlighting.highlight_by_language(code, language) +
"</code></pre>").html_safe
end
end
2 changes: 0 additions & 2 deletions app/models/view_customize.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ class ViewCustomize < ActiveRecord::Base

validate :valid_pattern

attr_protected :id

TYPE_JAVASCRIPT = "javascript"
TYPE_CSS = "css"

Expand Down
20 changes: 10 additions & 10 deletions app/views/view_customizes/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,36 @@

<table class="box view_customize">
<tr>
<th><%=h l(:field_path_pattern) %>:</th>
<th><%=h l(:field_path_pattern) %></th>
<td><%=h @view_customize.path_pattern %></td>
</tr>
<tr>
<th><%=h l(:field_insertion_position) %>:</th>
<th><%=h l(:field_insertion_position) %></th>
<td><%=h l(@view_customize.insertion_position_label) %></td>
</tr>
<tr>
<th><%=h l(:field_customize_type) %>:</th>
<th><%=h l(:field_customize_type) %></th>
<td><%=h l(@view_customize.customize_type_label) %></td>
</tr>
<tr>
<th><%=h l(:field_code) %>:</th>
<td><%= highlight_by_language(
@view_customize.code, @view_customize.is_javascript? ? :js : :css) %></td>
<th><%=h l(:field_code) %></th>
<td><div><%= highlight_by_language(
@view_customize.code, @view_customize.is_javascript? ? :js : :css) %></div></td>
</tr>
<tr>
<th><%=h l(:field_comments) %>:</th>
<th><%=h l(:field_comments) %></th>
<td><%=h @view_customize.comments %></td>
</tr>
<tr>
<th><%=h l(:field_is_enabled) %>:</th>
<th><%=h l(:field_is_enabled) %></th>
<td><%=h @view_customize.is_enabled ? l(:general_text_yes) : l(:general_text_no) %></td>
</tr>
<tr>
<th><%=h l(:field_is_private) %>:</th>
<th><%=h l(:field_is_private) %></th>
<td><%=h @view_customize.is_private ? l(:general_text_yes) : l(:general_text_no) %></td>
</tr>
<tr>
<th><%=h l(:field_author) %>:</th>
<th><%=h l(:field_author) %></th>
<td><%=h @view_customize.author.name unless @view_customize.author == nil %></td>
</tr>
</table>
15 changes: 10 additions & 5 deletions assets/stylesheets/view_customize.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,30 @@ table.view_customize.list tr.private {

table.view_customize.box {
width: 100%;
table-layout: fixed;
}

table.view_customize.box th {
text-align: right;
vertical-align: top;
width: 10%;
padding: 0 10px;
white-space: nowrap;
width: 160px;
padding: 2px 10px 2px 0px;
}

table.view_customize.box td {
vertical-align: top;
padding: 2px;
}

table.view_customize.box td pre {
margin: 0;
padding: 2px 4px;
background-color: #FFFFFF;
border: 1px solid #E4E4E4;
background-color: #fafafa;
border: 1px solid #e2e2e2;
border-radius: 3px;
width: auto;
overflow-x: auto;
overflow-y: hidden;
}

textarea#view_customize_code {
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/001_create_view_customizes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class CreateViewCustomizes < ActiveRecord::Migration
class CreateViewCustomizes < ActiveRecord::CompatibleLegacyMigration.migration_class
def change
create_table :view_customizes do |t|
t.string :path_pattern
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/002_add_column_view_customizes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class AddColumnViewCustomizes < ActiveRecord::Migration
class AddColumnViewCustomizes < ActiveRecord::CompatibleLegacyMigration.migration_class
def up
add_column :view_customizes, :is_enabled, :boolean, :null => false, :default => true
add_column :view_customizes, :is_private, :boolean, :null => false, :default => false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class AddInsertionPositionToViewCustomizes < ActiveRecord::Migration
class AddInsertionPositionToViewCustomizes < ActiveRecord::CompatibleLegacyMigration.migration_class
def up
add_column :view_customizes, :insertion_position, :string, :null => false, :default => "html_head"

Expand Down
2 changes: 1 addition & 1 deletion db/migrate/004_add_comments_to_view_customizes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class AddCommentsToViewCustomizes < ActiveRecord::Migration
class AddCommentsToViewCustomizes < ActiveRecord::CompatibleLegacyMigration.migration_class
def up
add_column :view_customizes, :comments, :string, :null => true
end
Expand Down
3 changes: 2 additions & 1 deletion init.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
require_dependency 'view_customize/view_hook'

Redmine::Plugin.register :view_customize do
requires_redmine :version_or_higher => '3.1.0'
name 'View Customize plugin'
author 'onozaty'
description 'View Customize plugin for Redmine'
version '1.2.2'
version '2.0.0'
url 'https://github.com/onozaty/redmine-view-customize'
author_url 'https://github.com/onozaty'

Expand Down

0 comments on commit f4bf47b

Please sign in to comment.