Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 28 additions & 7 deletions app/controllers/pastes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ class PastesController < ApplicationController

before_filter :find_project, :authorize

accept_key_auth :index
accept_rss_auth :index
accept_api_auth :index, :show, :download, :create, :update, :destroy

def index
@limit = per_page_option
Expand All @@ -40,6 +41,7 @@ def index
respond_to do |format|
format.html { render :layout => false if request.xhr? }
format.atom { render_feed(@pastes, :title => (@project ? @project.name : Setting.app_title) + ": " + l(:label_paste_plural)) }
format.api
end
end

Expand All @@ -63,10 +65,18 @@ def create
@paste = @project.pastes.build(params[:paste])
@paste.author = User.current
if @paste.save
flash[:notice] = l(:notice_paste_created)
redirect_to @paste
respond_to do |format|
format.html {
flash[:notice] = l(:notice_paste_created)
redirect_to @paste
}
format.api { render :action => 'show', :status => :created, :location => paste_url(@paste) }
end
else
render(params[:fork].blank? ? :new : :edit)
respond_to do |format|
format.html { render(params[:fork].blank? ? :new : :edit) }
format.api { render_validation_errors(@paste) }
end
end
end

Expand All @@ -76,17 +86,28 @@ def update
else
if @paste.update_attributes(params[:paste])
flash[:notice] = l(:notice_paste_updated)
redirect_to @paste

respond_to do |format|
format.html { redirect_to @paste }
format.api { head :ok }
end
else
render :edit
respond_to do |format|
format.html { render :edit }
format.api { render_validation_errors(@paste) }
end
end
end
end

def destroy
@paste.destroy
flash[:notice] = l(:notice_paste_destroyed)
redirect_to pastes_path(:project_id => @project.id)

respond_to do |format|
format.html { redirect_to pastes_path(:project_id => @project.id) }
format.api { head :ok }
end
end

private
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/pastes_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,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

Expand Down
3 changes: 2 additions & 1 deletion app/models/paste.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Paste < ActiveRecord::Base
belongs_to :project
belongs_to :author, :class_name => 'User'

named_scope :for_project, lambda { |project|
scope :for_project, lambda { |project|
{ :conditions => { :project_id => project } }
}

Expand All @@ -50,6 +50,7 @@ def description
SHORT_TEXT_LIMIT = 100

def short_text
return "" if text.nil?
if text.length < SHORT_TEXT_LIMIT
text
else
Expand Down
4 changes: 2 additions & 2 deletions app/views/pastes/_authorship.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<%= authoring paste.created_on, paste.author %>.
<%= authoring(paste.created_on, paste.author).html_safe %>.

<% 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 %>
8 changes: 5 additions & 3 deletions app/views/pastes/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,23 @@
<%= render :partial => "authorship", :locals => { :paste => @paste } %>
</p>

<% labelled_tabular_form_for :paste, @paste,
<%= labelled_form_for @paste,
:url => { :action => "update", :id => @paste },
:html => { :method => :put } do |f| %>
<div class="box">
<fieldset class="tabular">
<%= hidden_field_tag "fork" %>

<p><%= f.text_field :title, :label => :field_paste_title %></p>
<p><%= f.select :lang, pastebin_language_choices,
:label => :field_paste_lang %></p>
<p><%= f.text_area :text, :label => :field_paste_text,
:rows => 25, :cols => 80 %></p>
</fieldset>
</div>

<%=l :text_paste_update_or_make_new,
<%=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'") %>
:onclick => "$('fork').value = 'yes'")).html_safe %>
<% end %>
17 changes: 17 additions & 0 deletions app/views/pastes/index.api.rsb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
api.array :pastes, api_meta(:total_count => @pastes_count, :offset => @offset, :limit => @limit) do
@pastes.each do |paste|
api.paste do
api.id paste.id
api.author_id paste.author_id
api.project_id paste.project_id

api.lang paste.lang
api.title paste.title
api.text paste.text

api.created_on paste.created_on
api.updated_on paste.updated_on
end
end
end

48 changes: 36 additions & 12 deletions app/views/pastes/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,21 @@

<% content_for :header_tags do %>
<style type="text/css">
.paste .timestamp {
font-size: 90%;
.paste .right {
font-size: 80%;
float: right;
margin-left: 2em;
width: 30%;
display: inline-block;
text-align: right;
}

.paste .authorship {
font-size: 80%;
}

.paste code {
color: #aaa;
}
</style>
<% end %>
Expand All @@ -16,19 +29,30 @@
<p class="nodata"><%= l(:label_no_data) %></p>
<% else %>
<% @pastes.each do |paste| %>
<p class="paste">
<%= paste_timestamp(paste) %>&nbsp;&ndash;
<%= link_to_paste paste %>&nbsp;&ndash;
<div class="paste">

<p class='right'>
<strong class='lang'><%= pastebin_language_name(paste.lang) %></strong>
<br>
<span class='links'>
<%= manage_paste_links(paste).html_safe %>
</span>
</p>

<%= link_to_paste paste %>
<% unless @project %>
<%= link_to_project paste.project %>&nbsp;&ndash;
<%= link_to_project(paste.project).html_safe %>
<% end %>
<%= pastebin_language_name(paste.lang) %>&nbsp;&ndash;
<code><%=h paste.short_text %></code><br>

<%= render :partial => "authorship", :locals => { :paste => paste } %>
<br>
<code><%= paste.short_text %></code>
<br>
<br>
<span class='authorship'>
<%= render :partial => "authorship", :locals => { :paste => paste } %>
</span>

<%= manage_paste_links(paste) %>
</p>
</div>
<div style="clear:both"><hr></div>
<% end %>

<p class="pagination">
Expand Down
4 changes: 3 additions & 1 deletion app/views/pastes/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

<h2><%=l :label_paste_new %></h2>

<% labelled_tabular_form_for :paste, @paste, :url => { :action => "create",
<%= labelled_form_for @paste, :url => { :action => "create",
:project_id => @paste.project.id } do |f| %>
<div class="box">
<fieldset class="tabular">
<p><%= f.text_field :title, :label => :field_paste_title %></p>
<p><%= f.select :lang, pastebin_language_choices,
:label => :field_paste_lang %></p>
<p><%= f.text_area :text, :label => :field_paste_text,
:rows => 25, :cols => 80 %></p>
</fieldset>
</div>
<%= f.submit l(:button_paste_submit) %>
<% end %>
12 changes: 12 additions & 0 deletions app/views/pastes/show.api.rsb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
api.paste do
api.id @paste.id
api.author_id @paste.author_id
api.project_id @paste.project_id

api.lang @paste.lang
api.title @paste.title
api.text @paste.text

api.created_on @paste.created_on
api.updated_on @paste.updated_on
end
6 changes: 3 additions & 3 deletions app/views/pastes/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -27,11 +27,11 @@ table.CodeRay td.line_numbers {
</p>

<div class="paste">
<%= highlighted_content_for_paste(@paste) %>
<%= highlighted_content_for_paste(@paste).html_safe %>
</div>

<p>
<%= manage_paste_links(@paste) %>
<%= manage_paste_links(@paste).html_safe %>
</p>

<%= render "sidebar" %>
27 changes: 22 additions & 5 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
ActionController::Routing::Routes.draw do |map|
map.resources :pastes, :only => [:index, :show],
:member => { :download => :get }
map.resources :pastes, :path_prefix => '/projects/:project_id',
:member => { :download => :get }
RedmineApp::Application.routes.draw do

resources :pastes do
member do
get 'download'
end
end

resources :projects do
resources :pastes do
member do
get 'download'
end
end
end



# map.resources :pastes, :only => [:index, :show],
# :member => { :download => :get }
# map.resources :pastes, :path_prefix => '/projects/:project_id',
# :member => { :download => :get }
end
18 changes: 8 additions & 10 deletions init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,20 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

YAML::ENGINE.yamler = 'syck'
require 'redmine'
require 'dispatcher'

require_dependency 'redmine_pastebin/view_hooks'

Dispatcher.to_prepare :redmine_pastebin do
require_dependency 'project'
require_dependency 'user'
require_dependency 'project'
require_dependency 'user'

unless Project.included_modules.include? RedminePastebin::ProjectPastesPatch
Project.send(:include, RedminePastebin::ProjectPastesPatch)
end
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
unless User.included_modules.include? RedminePastebin::UserPastesPatch
User.send(:include, RedminePastebin::UserPastesPatch)
end

Redmine::Plugin.register :redmine_pastebin do
Expand Down