[ARVADOS] created: cd1c3d8ddae9b743fe557881005e08a63785e49e
git at public.curoverse.com
git at public.curoverse.com
Thu Aug 7 14:53:12 EDT 2014
at cd1c3d8ddae9b743fe557881005e08a63785e49e (commit)
commit cd1c3d8ddae9b743fe557881005e08a63785e49e
Author: Phil Hodgson <bitbucket at philhodgson.net>
Date: Thu Aug 7 14:48:24 2014 -0400
Can now specify in an arvados model that an element should be rendered as textile (refs #2917, #3354)
For an example of activation of this feature see the Group model, on the description attribute, in this commit.
diff --git a/apps/workbench/app/assets/javascripts/editable.js b/apps/workbench/app/assets/javascripts/editable.js
index 76a129b..25d38a9 100644
--- a/apps/workbench/app/assets/javascripts/editable.js
+++ b/apps/workbench/app/assets/javascripts/editable.js
@@ -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).html(response[textileAttr]);
+ }
+ }
return;
},
error: function(response, newValue) {
diff --git a/apps/workbench/app/assets/stylesheets/application.css.scss b/apps/workbench/app/assets/stylesheets/application.css.scss
index c986f03..7d87dc3 100644
--- a/apps/workbench/app/assets/stylesheets/application.css.scss
+++ b/apps/workbench/app/assets/stylesheets/application.css.scss
@@ -244,3 +244,7 @@ div.pane-content iframe {
width: 100%;
border: none;
}
+
+span.editable-textile {
+ display: inline-block;
+}
diff --git a/apps/workbench/app/controllers/application_controller.rb b/apps/workbench/app/controllers/application_controller.rb
index df95335..5f05dee 100644
--- a/apps/workbench/app/controllers/application_controller.rb
+++ b/apps/workbench/app/controllers/application_controller.rb
@@ -1,6 +1,7 @@
class ApplicationController < ActionController::Base
include ArvadosApiClientHelper
include ApplicationHelper
+ include ActionView::Helpers::OutputSafetyHelper
respond_to :html, :json, :js
protect_from_forgery
@@ -173,7 +174,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(@object)) }
+ f.json do
+ extra_attrs = { href: url_for(@object) }
+ @object.textile_attributes.each do |textile_attr|
+ extra_attrs.merge!({ "#{textile_attr}Textile" => raw( RedCloth.new(@object.attributes[textile_attr].to_s).to_html ) })
+ end
+ render json: @object.attributes.merge(extra_attrs)
+ end
f.html {
if params['tab_pane']
comparable = self.respond_to? :compare
diff --git a/apps/workbench/app/helpers/application_helper.rb b/apps/workbench/app/helpers/application_helper.rb
index 1130036..b2bdbcf 100644
--- a/apps/workbench/app/helpers/application_helper.rb
+++ b/apps/workbench/app/helpers/application_helper.rb
@@ -158,7 +158,9 @@ module ApplicationHelper
input_type = 'text'
end
+ is_textile = object.textile_attributes.andand.include?(attr)
attrvalue = attrvalue.to_json if attrvalue.is_a? Hash or attrvalue.is_a? Array
+ rendervalue = is_textile ? raw( RedCloth.new(attrvalue.to_s).to_html ) : attrvalue
ajax_options = {
"data-pk" => {
@@ -176,7 +178,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 +186,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 ? '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
diff --git a/apps/workbench/app/models/arvados_base.rb b/apps/workbench/app/models/arvados_base.rb
index 1dac43f..d38ca78 100644
--- a/apps/workbench/app/models/arvados_base.rb
+++ b/apps/workbench/app/models/arvados_base.rb
@@ -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
diff --git a/apps/workbench/app/models/group.rb b/apps/workbench/app/models/group.rb
index 558c587..a91b729 100644
--- a/apps/workbench/app/models/group.rb
+++ b/apps/workbench/app/models/group.rb
@@ -30,4 +30,8 @@ class Group < ArvadosBase
writable_by and
writable_by.index(current_user.uuid)
end
+
+ def textile_attributes
+ [ 'description' ]
+ end
end
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list