Merge branch 'master' into 3354-render-textile
authorPhil Hodgson <bitbucket@philhodgson.net>
Wed, 20 Aug 2014 13:04:54 +0000 (09:04 -0400)
committerPhil Hodgson <bitbucket@philhodgson.net>
Wed, 20 Aug 2014 13:04:54 +0000 (09:04 -0400)
Conflicts (resolved):
apps/workbench/app/controllers/application_controller.rb

apps/workbench/app/assets/javascripts/editable.js
apps/workbench/app/assets/stylesheets/application.css.scss
apps/workbench/app/controllers/application_controller.rb
apps/workbench/app/controllers/links_controller.rb
apps/workbench/app/helpers/application_helper.rb
apps/workbench/app/models/arvados_base.rb
apps/workbench/app/models/group.rb
apps/workbench/config/initializers/redcloth.rb [new file with mode: 0644]

index 76a129b2bfbb0b895b66484c2214a2dc7f23131e..dc54bda7af79a17f7a7eae3ec1aa9d059ac9851d 100644 (file)
@@ -55,6 +55,12 @@ $(document).
                     if (response.href) {
                         $(this).editable('option', 'url', response.href);
                     }
+                    if ($(this).attr('data-name')) {
+                        var textileAttr = $(this).attr('data-name') + 'Textile';
+                        if (response[textileAttr]) {
+                            $(this).attr('data-textile', response[textileAttr]);
+                        }
+                    }
                     return;
                 },
                 error: function(response, newValue) {
@@ -75,6 +81,10 @@ $(document).
                 // information if it appears elsewhere on the page.
                 if (reason != 'save') return;
                 var html = $(this).html();
+                if( $(this).attr('data-textile') ) {
+                    html = $(this).attr('data-textile');
+                    $(this).html(html);
+                }
                 var uuid = $(this).attr('data-object-uuid');
                 var attr = $(this).attr('data-name');
                 var edited = this;
index c986f034bcc6a0e19f8525659201a3fe8f6cb74c..7d87dc3ac51fc55afaddc16b6069dcc9bb585a79 100644 (file)
@@ -244,3 +244,7 @@ div.pane-content iframe {
   width: 100%;
   border: none;
 }
+
+span.editable-textile {
+  display: inline-block;
+}
index 5c99c15abc62544f79c4bca6f148da051f8e59a8..d2f4ed44b240990b5c611c34d0103a478924c7f4 100644 (file)
@@ -202,7 +202,13 @@ class ApplicationController < ActionController::Base
       return render_not_found("object not found")
     end
     respond_to do |f|
-      f.json { render json: @object.attributes.merge(href: url_for(action: :show, id: @object)) }
+      f.json do
+        extra_attrs = { href: url_for(action: :show, id: @object) }
+        @object.textile_attributes.each do |textile_attr|
+          extra_attrs.merge!({ "#{textile_attr}Textile" => view_context.render_content_from_database(@object.attributes[textile_attr]) })
+        end
+        render json: @object.attributes.merge(extra_attrs)
+      end
       f.html {
         if params['tab_pane']
           render_pane params['tab_pane']
index 78529c149a984880a0270f5ad9baadca0de4106b..fd51fb161614c36ec137f84948ec49631be61e2c 100644 (file)
@@ -1,2 +1,9 @@
 class LinksController < ApplicationController
+  def show
+    if @object.link_class == 'name' and
+        Collection == ArvadosBase::resource_class_for_uuid(@object.head_uuid)
+      return redirect_to collection_path(@object.uuid)
+    end
+    super
+  end
 end
index 428c14f8282961f65e6ad69e9197794f62997d54..a219cd5cc3423820ea3c029e6c6c78e57ca24095 100644 (file)
@@ -12,7 +12,7 @@ module ApplicationHelper
   end
 
   def render_content_from_database(markup)
-    raw RedCloth.new(markup).to_html
+    raw RedCloth.new(markup.to_s).to_html(:refs_arvados, :textile) if markup
   end
 
   def human_readable_bytes_html(n)
@@ -143,9 +143,12 @@ module ApplicationHelper
     if !object.attribute_editable?(attr, :ever) or
         (!object.editable? and
          !object.owner_uuid.in?(my_projects.collect(&:uuid)))
-      return ((attrvalue && attrvalue.length > 0 && attrvalue) ||
-              (attr == 'name' and object.andand.default_name) ||
-              '(none)')
+      if attrvalue && attrvalue.length > 0
+        return render_textile_if_textile( object, attr, attrvalue )
+      else
+        return (attr == 'name' and object.andand.default_name) ||
+                '(none)'
+      end
     end
 
     input_type = 'text'
@@ -159,6 +162,7 @@ module ApplicationHelper
     end
 
     attrvalue = attrvalue.to_json if attrvalue.is_a? Hash or attrvalue.is_a? Array
+    rendervalue = render_textile_if_textile( object, attr, attrvalue )
 
     ajax_options = {
       "data-pk" => {
@@ -176,7 +180,7 @@ module ApplicationHelper
     @unique_id ||= (Time.now.to_f*1000000).to_i
     span_id = object.uuid.to_s + '-' + attr.to_s + '-' + (@unique_id += 1).to_s
 
-    span_tag = content_tag 'span', attrvalue.to_s, {
+    span_tag = content_tag 'span', rendervalue, {
       "data-emptytext" => (object.andand.default_name || 'none'),
       "data-placement" => "bottom",
       "data-type" => input_type,
@@ -184,8 +188,9 @@ module ApplicationHelper
       "data-name" => attr,
       "data-object-uuid" => object.uuid,
       "data-toggle" => "manual",
+      "data-value" => attrvalue,
       "id" => span_id,
-      :class => "editable"
+      :class => "editable #{is_textile?( object, attr ) ? 'editable-textile' : ''}"
     }.merge(htmloptions).merge(ajax_options)
     edit_button = raw('<a href="#" class="btn btn-xs btn-default btn-nodecorate" data-toggle="x-editable tooltip" data-toggle-selector="#' + span_id + '" data-placement="top" title="' + (htmloptions[:tiptitle] || 'edit') + '"><i class="fa fa-fw fa-pencil"></i></a>')
     if htmloptions[:btnplacement] == :left
@@ -443,4 +448,13 @@ module ApplicationHelper
       nil
     end
   end
+
+private
+  def is_textile?( object, attr )
+    is_textile = object.textile_attributes.andand.include?(attr)
+  end
+
+  def render_textile_if_textile( object, attr, attrvalue )
+    is_textile?( object, attr ) ? render_content_from_database(attrvalue) : attrvalue
+  end
 end
index 1dac43fa61a7ffbd2c100b3f932b4568f174ee73..d38ca7822d69998f67d35b5d5c97fb62db015058 100644 (file)
@@ -303,6 +303,11 @@ class ArvadosBase < ActiveRecord::Base
     self.to_s.underscore.humanize
   end
 
+  # Array of strings that are names of attributes that should be rendered as textile.
+  def textile_attributes
+    []
+  end
+
   def self.creatable?
     current_user
   end
index 558c587a1c9c83d3a0bb824475e0b8f2553e4a0d..a91b729c86d1ba12220a5813da75ba2b7a44172f 100644 (file)
@@ -30,4 +30,8 @@ class Group < ArvadosBase
       writable_by and
       writable_by.index(current_user.uuid)
   end
+
+  def textile_attributes
+    [ 'description' ]
+  end
 end
diff --git a/apps/workbench/config/initializers/redcloth.rb b/apps/workbench/config/initializers/redcloth.rb
new file mode 100644 (file)
index 0000000..4c242de
--- /dev/null
@@ -0,0 +1,22 @@
+module RedClothArvadosLinkExtension
+
+  class RedClothViewBase < ActionView::Base
+    include ApplicationHelper
+    include ActionView::Helpers::UrlHelper
+    include Rails.application.routes.url_helpers
+
+    def helper_link_to_if_arvados_object(link, opts)
+      link_to_if_arvados_object(link, opts)
+    end
+  end
+
+  def refs_arvados(text)
+    text.gsub!(/"(?!\s)([^"]*\S)":(\S+)/) do
+      text, link = $~[1..2]
+      arvados_link = RedClothViewBase.new.helper_link_to_if_arvados_object(link, { :link_text => text })
+      arvados_link ? arvados_link : "#{text}:#{link}"
+    end
+  end
+end
+
+RedCloth.send(:include, RedClothArvadosLinkExtension)