Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Redmine-2.x compatibility.

  • Loading branch information...
commit c3c5977d7e2cc45baa0a74f044788a306c48400e 1 parent d83ef0c
@ashcmd ashcmd authored
View
5 README.rdoc
@@ -2,9 +2,12 @@
A real pastebin plugin for Redmine.
+For Redmine versions prior to 2.x, check out the pre-2.x branch.
+
= Installation Notes
-$ script/plugin install ...
+Use git to clone to plugins/, then run the DB migrations:
+
$ rake db:migrate_plugins
Don't forget to setup roles permissions in the Pastes section.
View
29 app/helpers/pastes_helper.rb
@@ -81,7 +81,7 @@ def highlighted_content_for_paste(paste)
# TODO: hard-coding code-ray for :table option
content_tag :div, :class => "syntaxhl box" do
- ::CodeRay.scan(paste.text, paste.lang).html(:line_numbers => :table)
+ ::CodeRay.scan(paste.text, paste.lang).html(:line_numbers => :table).html_safe
end
end
@@ -97,38 +97,39 @@ def url_to_paste(action, paste = nil)
end
def link_to_paste(paste)
- link_to paste.title, paste
+ link_to(paste.title, paste)
end
def edit_paste_link(paste, title = l(:button_edit))
- link_to_if_authorized title, url_to_paste("edit", paste),
- :class => "icon icon-edit"
+ link_to_if_authorized(title, url_to_paste("edit", paste),
+ :class => "icon icon-edit")
end
def delete_paste_link(paste, title = l(:button_delete))
- link_to_if_authorized title, url_to_paste("destroy", paste),
- :class => "icon icon-del",
- :method => :delete, :confirm => l(:text_paste_delete_confirmation)
+ link_to_if_authorized(title, url_to_paste("destroy", paste),
+ :class => "icon icon-del",
+ :method => :delete,
+ :confirm => l(:text_paste_delete_confirmation))
end
def download_paste_link(paste, title = l(:button_download))
- link_to title, url_to_paste("download", paste),
- :class => "icon icon-save"
+ link_to(title, url_to_paste("download", paste),
+ :class => "icon icon-save")
end
def manage_paste_links(paste)
[edit_paste_link(paste),
delete_paste_link(paste),
- download_paste_link(paste)].join("\n")
+ download_paste_link(paste)].join("\n").html_safe
end
def link_to_all_pastes
- link_to l(:label_paste_view_all), url_to_paste("index"),
- :class => "icon icon-multiple"
+ link_to(l(:label_paste_view_all), url_to_paste("index"),
+ :class => "icon icon-multiple")
end
def link_to_new_paste
- link_to_if_authorized l(:label_paste_new), url_to_paste("new"),
- :class => "icon icon-add"
+ link_to_if_authorized(l(:label_paste_new), url_to_paste("new"),
+ :class => "icon icon-add")
end
end
View
14 app/models/paste.rb
@@ -26,17 +26,17 @@ class Paste < ActiveRecord::Base
belongs_to :project
belongs_to :author, :class_name => 'User'
- named_scope :for_project, lambda { |project|
- { :conditions => { :project_id => project } }
+ scope :for_project, lambda { |project|
+ where({ :project_id => project })
}
- named_scope :secure, :conditions => "access_token IS NOT NULL"
- named_scope :visible_to, lambda { |user|
- { :conditions => (user.admin? ? nil : ["access_token IS NULL OR author_id = ?", user.id]) }
+ scope :secure, where("access_token IS NOT NULL")
+ scope :visible_to, lambda { |user|
+ where(user.admin? ? nil : ["access_token IS NULL OR author_id = ?", user.id])
}
- named_scope :expired, :conditions => "expires_at <= current_timestamp"
- default_scope :conditions => "expires_at IS NULL OR expires_at > current_timestamp"
+ scope :expired, where("expires_at <= current_timestamp")
+ default_scope where("expires_at IS NULL OR expires_at > current_timestamp")
acts_as_searchable :columns => ["#{table_name}.title", "#{table_name}.text"],
:include => :project
View
2  app/views/hooks/_redmine_pastebin_all_pastes_link.html.erb
@@ -1 +1 @@
-<%= link_to(l(:label_paste_view_all), { :controller => 'pastes' }) + ' |' if User.current.allowed_to?(:view_pastes, nil, :global => true) %>
+<%= (link_to(l(:label_paste_view_all), { :controller => 'pastes' }) + ' |').html_safe if User.current.allowed_to?(:view_pastes, nil, :global => true) %>
View
2  app/views/pastes/_authorship.html.erb
@@ -1,7 +1,7 @@
<%= authoring paste.created_on, paste.author %>.
<% if paste.updated_on != paste.created_on %>
- <%= l(:label_updated_time, time_tag(paste.updated_on)) %>.
+ <%= l(:label_updated_time, time_tag(paste.updated_on)).html_safe %>.
<% end %>
<% if paste.expires_at.present? %>
<span style="color: red;"><%= l(:label_paste_expires_at) %> <%= format_time(paste.expires_at) %></span>
View
12 app/views/pastes/edit.html.erb
@@ -1,12 +1,12 @@
<% html_title @paste.title %>
-<h2><%=l :label_paste_edit, :link => link_to_paste(@paste) %></h2>
+<h2><%= l(:label_paste_edit, :link => link_to_paste(@paste)).html_safe %></h2>
<p>
<%= render :partial => "authorship", :locals => { :paste => @paste } %>
</p>
-<% labelled_tabular_form_for :paste, @paste,
+<%= labelled_tabular_form_for @paste,
:url => { :action => "update", :id => @paste },
:html => { :method => :put } do |f| %>
<div class="box">
@@ -19,8 +19,8 @@
:rows => 25, :cols => 80 %></p>
</div>
-<%=l :text_paste_update_or_make_new,
- :update => f.submit(l(:button_paste_update)),
- :make_new => submit_tag(l(:button_paste_make_new),
- :onclick => "$('fork').value = 'yes'") %>
+<%= l(:text_paste_update_or_make_new,
+ :update => f.submit(l(:button_paste_update)),
+ :make_new => submit_tag(l(:button_paste_make_new),
+ :onclick => "$('fork').value = 'yes'")).html_safe %>
<% end %>
View
4 app/views/pastes/new.html.erb
@@ -2,8 +2,8 @@
<h2><%=l :label_paste_new %></h2>
-<% labelled_tabular_form_for :paste, @paste, :url => { :action => "create",
- :project_id => @paste.project.id } do |f| %>
+<%= labelled_tabular_form_for @paste,
+ :url => { :action => "create", :project_id => @paste.project.id } do |f| %>
<div class="box">
<p><%= f.text_field :title, :label => :field_paste_title %></p>
<p><%= f.select :lang, pastebin_language_choices,
View
2  app/views/pastes/show.html.erb
@@ -18,7 +18,7 @@ table.CodeRay td.line_numbers {
<h2><%=h @paste.title %></h2>
<p>
-<%=l :label_paste_link_here, :link => link_to(paste_url(@paste), @paste) %>
+<%= l(:label_paste_link_here, :link => link_to(paste_url(@paste), @paste)).html_safe %>
</p>
<p>
View
18 config/routes.rb
@@ -1,8 +1,14 @@
-ActionController::Routing::Routes.draw do |map|
- # new paste can be only created on a project
- map.resources :pastes, :except => :new,
- :member => { :download => :get }
+routedef = Proc.new do |options|
+ resources :pastes, options do
+ member do
+ get :download
+ end
+ end
+end
+
+# new paste can be only created on a project
+routedef.call :except => :new
- map.resources :pastes, :path_prefix => '/projects/:project_id',
- :member => { :download => :get }
+scope '/projects/:project_id', :as => 'per_project' do
+ routedef.call({})
end
View
33 init.rb
@@ -17,32 +17,16 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
require 'redmine'
-require 'dispatcher'
-
-require_dependency 'redmine_pastebin/view_hooks'
-
-Dispatcher.to_prepare :redmine_pastebin do
- require_dependency 'project'
- require_dependency 'user'
-
- unless Project.included_modules.include? RedminePastebin::ProjectPastesPatch
- Project.send(:include, RedminePastebin::ProjectPastesPatch)
- end
-
- unless User.included_modules.include? RedminePastebin::UserPastesPatch
- User.send(:include, RedminePastebin::UserPastesPatch)
- end
-end
Redmine::Plugin.register :redmine_pastebin do
name 'Redmine Pastebin plugin'
author 'Alex Shulgin <ash@commandprompt.com>'
description 'A real pastebin plugin for redmine'
- version '0.0.1'
+ version '0.2.0'
url 'https://github.com/commandprompt/redmine_pastebin/'
# author_url 'http://example.com/about'
- requires_redmine :version_or_higher => '1.1.0'
+ requires_redmine :version_or_higher => '2.0.x'
project_module :pastes do
permission :view_pastes, :pastes => [:index, :show, :download]
@@ -63,3 +47,16 @@
Redmine::Search.map do |search|
search.register :pastes
end
+
+prepare_block = Proc.new do
+ Project.send(:include, RedminePastebin::ProjectPastesPatch)
+ User.send(:include, RedminePastebin::UserPastesPatch)
+end
+
+if Rails.env.development?
+ ActionDispatch::Reloader.to_prepare { prepare_block.call }
+else
+ prepare_block.call
+end
+
+require_dependency 'redmine_pastebin/view_hooks'
Please sign in to comment.
Something went wrong with that request. Please try again.