Permalink
Browse files

Initial commit.

  • Loading branch information...
0 parents commit 2d082c9b7f506ea7736461694d8be0a632a07851 root committed Mar 3, 2011
17 LICENSE
@@ -0,0 +1,17 @@
+redmine_pastebin -- A real pastebin plugin for Redmine.
+
+Copyright (C) 2011 Alex Shuglin <ash@commandprompt.com>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
@@ -0,0 +1,3 @@
+= redmine_pastebin
+
+A real pastebin plugin for Redmine.
@@ -0,0 +1,76 @@
+# redmine_pastebin -- A real pastebin plugin for Redmine.
+#
+# Copyright (C) 2011 Alex Shuglin <ash@commandprompt.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+class PastesController < ApplicationController
+ unloadable
+
+ before_filter :find_project, :authorize
+
+ def index
+ @pastes = @project.pastes.all(:order => "pastes.created_at DESC")
+ end
+
+ def show
+ end
+
+ def new
+ @paste = @project.pastes.build
+ end
+
+ def edit
+ end
+
+ def create
+ @paste = @project.pastes.build(params[:paste])
+ @paste.author = User.current
+ if @paste.save
+ flash[:notice] = "Pasted successfully"
+ redirect_to @paste
+ else
+ render :new
+ end
+ end
+
+ def update
+ if @paste.update_attributes(params[:paste])
+ @paste.update_attribute(:author_id, User.current.id)
+
+ flash[:notice] = "Pasted updated successfully"
+ redirect_to @paste
+ else
+ render :edit
+ end
+ end
+
+ def destroy
+ @paste.destroy
+ flash[:notice] = "Paste destroyed"
+ redirect_to pastes_path(:project_id => @project.id)
+ end
+
+ private
+
+ def find_project
+ if params[:project_id].present?
+ @project = Project.find(params[:project_id])
+ else
+ @paste = Paste.find(params[:id])
+ @project = @paste.project
+ end
+ end
+end
@@ -0,0 +1,65 @@
+# redmine_pastebin -- A real pastebin plugin for Redmine.
+#
+# Copyright (C) 2011 Alex Shuglin <ash@commandprompt.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+require 'coderay'
+
+module PastesHelper
+ PASTEBIN_LANG_HASH = {
+ "C" => "C",
+ "C++" => "CPlusPlus",
+ "Ruby" => "Ruby",
+ "Python" => "Python",
+ "JavaScript" => "JavaScript"
+ }
+
+ def pastebin_language_choices
+ PASTEBIN_LANG_HASH.map { |k,v| [k, v] }
+ end
+
+ def pastebin_language_name(lang)
+ PASTEBIN_LANG_HASH.invert[lang]
+ end
+
+ def highlighted_content_for_paste(paste)
+ #Redmine::SyntaxHighlighting.highlight_by_language(paste.text, paste.lang)
+
+ # TODO: hard-coding code-ray for :table option
+ content_tag :div, :class => "syntaxhl" do
+ ::CodeRay.scan(paste.text, paste.lang).html(:line_numbers => :table)
+ end
+ end
+
+ PASTEBIN_TEXT_PREVIEW_LIMIT = 100
+
+ def pastebin_text_preview(text)
+ if text.length < PASTEBIN_TEXT_PREVIEW_LIMIT
+ text
+ else
+ text[0..PASTEBIN_TEXT_PREVIEW_LIMIT] + "..."
+ end
+ end
+
+ def edit_paste_link(paste, title = "Edit")
+ link_to title, edit_paste_path(paste), :class => "icon icon-edit"
+ end
+
+ def delete_paste_link(paste, title = "Delete")
+ link_to title, paste_path(paste), :class => "icon icon-del",
+ :method => :delete, :confirm => "Are you sure?"
+ end
+end
@@ -0,0 +1,26 @@
+# redmine_pastebin -- A real pastebin plugin for Redmine.
+#
+# Copyright (C) 2011 Alex Shuglin <ash@commandprompt.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+class Paste < ActiveRecord::Base
+ unloadable # really?
+
+ attr_accessible :text, :lang
+
+ belongs_to :project
+ belongs_to :author, :class_name => 'User'
+end
@@ -0,0 +1,14 @@
+<h2>Edit Paste #<%= @paste.id %></h2>
+
+<% form_for @paste do |f| %>
+ <p>
+ <%= f.label :lang, "Langauge" %>
+ <%= f.select :lang, pastebin_language_choices %>
+ </p>
+
+ <%= f.text_area :text, :rows => 25, :cols => 80 %>
+
+ <p>
+ <%= f.submit "Update paste!" %>
+ </p>
+<% end %>
@@ -0,0 +1,17 @@
+<div class="contextual">
+<%= link_to("New paste", new_paste_path(:project_id => @project), :class => 'icon icon-add') if User.current.allowed_to?(:manage_pastes, @project) %>
+</div>
+
+<h2>Pastes</h2>
+
+<% @pastes.each do |paste| %>
+ <p>
+ <%= link_to "Paste ##{paste.id}", paste %> -
+ <%= pastebin_language_name(paste.lang) %> -
+ <code><%=h pastebin_text_preview(paste.text) %></code><br>
+ Author: <%= link_to_user paste.author %>
+ at <%= format_date(paste.updated_at) %>
+ <%= edit_paste_link(paste) %>
+ <%= delete_paste_link(paste) %>
+ </p>
+<% end %>
@@ -0,0 +1,15 @@
+<h2>New Paste</h2>
+
+<% form_for @paste, :url => { :action => "create",
+ :project_id => @paste.project.id } do |f| %>
+ <p>
+ <%= f.label :lang, "Langauge" %>
+ <%= f.select :lang, pastebin_language_choices %>
+ </p>
+
+ <%= f.text_area :text, :rows => 25, :cols => 80 %>
+
+ <p>
+ <%= f.submit "Paste!" %>
+ </p>
+<% end %>
@@ -0,0 +1,20 @@
+<% content_for :header_tags do %>
+ <%= stylesheet_link_tag 'scm' %>
+<% end %>
+
+<h2>Paste #<%= @paste.id %></h2>
+
+<p>
+Link to this paste: <%= link_to paste_url(@paste), @paste %>
+</p>
+
+<p>
+Language: <%= pastebin_language_name(@paste.lang) %><br>
+Author: <%= link_to_user @paste.author %>
+at <%= format_date(@paste.updated_at) %>
+</p>
+
+<%= highlighted_content_for_paste(@paste) %>
+
+<%= edit_paste_link @paste, "Edit this paste" %>
+<%= delete_paste_link @paste, "Delete this paste" %>
@@ -0,0 +1,3 @@
+# English strings go here for Rails i18n
+en:
+ my_label: "My label"
@@ -0,0 +1,3 @@
+ActionController::Routing::Routes.draw do |map|
+ map.resources :pastes
+end
@@ -0,0 +1,15 @@
+class CreatePastes < ActiveRecord::Migration
+ def self.up
+ create_table :pastes do |t|
+ t.column :text, :text
+ t.column :lang, :string
+ t.column :author_id, :integer, :null => false
+ t.column :project_id, :integer, :null => false
+ t.timestamps
+ end
+ end
+
+ def self.down
+ drop_table :pastes
+ end
+end
Oops, something went wrong.

0 comments on commit 2d082c9

Please sign in to comment.