[Git][noosfero/noosfero][master] 3 commits: Adds element classes to attrs when parsing macros

Rodrigo Souto gitlab at mg.gitlab.com
Fri Mar 23 16:46:56 BRT 2018


Rodrigo Souto pushed to branch master at Noosfero / noosfero


Commits:
0ec463f9 by Gabriel Silva at 2018-03-02T23:41:04Z
Adds element classes to attrs when parsing macros

Signed-off-by: Gabriel Silva <gabriel93.silva at gmail.com>

- - - - -
eb96c1ff by Gabriel Silva at 2018-03-02T23:41:04Z
CommentParagraphPlugin: adds element classes to wrapper

Signed-off-by: Gabriel Silva <gabriel93.silva at gmail.com>

- - - - -
d0e9356f by Rodrigo Souto at 2018-03-23T19:46:39Z
Merge branch 'macro-classes' into 'master'

Adds element classes to attributes when parsing macros

See merge request noosfero/noosfero!1412
- - - - -


5 changed files:

- lib/noosfero/plugin/macro.rb
- plugins/comment_paragraph/lib/comment_paragraph_plugin/macros/allow_comment.rb
- plugins/comment_paragraph/test/unit/allow_comment_test.rb
- plugins/comment_paragraph/views/comment_paragraph_plugin_profile/_comment_paragraph.html.erb
- test/unit/macro_test.rb


Changes:

=====================================
lib/noosfero/plugin/macro.rb
=====================================
--- a/lib/noosfero/plugin/macro.rb
+++ b/lib/noosfero/plugin/macro.rb
@@ -43,6 +43,7 @@ class Noosfero::Plugin
     def convert(macro, source)
       macro_name = macro['data-macro']
       attrs = attributes(macro)
+      attrs['classes'] = macro.attr('class')
 
       begin
         content = parse(attrs, macro.inner_html, source)


=====================================
plugins/comment_paragraph/lib/comment_paragraph_plugin/macros/allow_comment.rb
=====================================
--- a/plugins/comment_paragraph/lib/comment_paragraph_plugin/macros/allow_comment.rb
+++ b/plugins/comment_paragraph/lib/comment_paragraph_plugin/macros/allow_comment.rb
@@ -5,7 +5,7 @@ end
 class CommentParagraphPlugin::AllowComment < Noosfero::Plugin::Macro
 
   def self.configuration
-    { :params => [] }
+    { params: [] }
   end
 
   def parse(params, inner_html, source)
@@ -13,11 +13,14 @@ class CommentParagraphPlugin::AllowComment < Noosfero::Plugin::Macro
     article = source
     @paragraph_comments_counts ||= article.paragraph_comments.without_spam.group(:paragraph_uuid).reorder(:paragraph_uuid).count
     count = @paragraph_comments_counts.fetch(paragraph_uuid, 0)
+    classes = params[:classes]
 
     proc {
       if controller.kind_of?(ContentViewerController) && article.comment_paragraph_plugin_activated?
-        render :partial => 'comment_paragraph_plugin_profile/comment_paragraph',
-               :locals => {:paragraph_uuid => paragraph_uuid, :article_id => article.id, :inner_html => inner_html, :count => count, :profile_identifier => article.profile.identifier }
+        render partial: 'comment_paragraph_plugin_profile/comment_paragraph',
+               locals: { paragraph_uuid: paragraph_uuid, article_id: article.id,
+                         inner_html: inner_html, count: count, classes: classes,
+                         profile_identifier: article.profile.identifier }
       else
         inner_html
       end


=====================================
plugins/comment_paragraph/test/unit/allow_comment_test.rb
=====================================
--- a/plugins/comment_paragraph/test/unit/allow_comment_test.rb
+++ b/plugins/comment_paragraph/test/unit/allow_comment_test.rb
@@ -24,10 +24,11 @@ class AllowCommentTest < ActiveSupport::TestCase
   end
 
   should 'parse contents to include comment paragraph view' do
-    content = macro.parse({:paragraph_uuid => comment.paragraph_uuid}, article.body, article)
+    attrs = { paragraph_uuid: comment.paragraph_uuid, classes: 'custom-class' }
+    content = macro.parse(attrs, article.body, article)
     controller.expects(:kind_of?).with(ContentViewerController).returns(true)
 
-    expects(:render).with({:partial => 'comment_paragraph_plugin_profile/comment_paragraph', :locals => {:paragraph_uuid => comment.paragraph_uuid, :article_id => article.id, :inner_html => article.body, :count => 1, :profile_identifier => profile.identifier} })
+    expects(:render).with({:partial => 'comment_paragraph_plugin_profile/comment_paragraph', :locals => {:classes => 'custom-class', :paragraph_uuid => comment.paragraph_uuid, :article_id => article.id, :inner_html => article.body, :count => 1, :profile_identifier => profile.identifier} })
     instance_eval(&content)
   end
 


=====================================
plugins/comment_paragraph/views/comment_paragraph_plugin_profile/_comment_paragraph.html.erb
=====================================
--- a/plugins/comment_paragraph/views/comment_paragraph_plugin_profile/_comment_paragraph.html.erb
+++ b/plugins/comment_paragraph/views/comment_paragraph_plugin_profile/_comment_paragraph.html.erb
@@ -1,4 +1,6 @@
-<div class="comment-paragraph-plugin comments" id="comment-paragraph-plugin_<%= paragraph_uuid %>" data-paragraph="<%= paragraph_uuid %>">
+<div class="comment-paragraph-plugin comments <%= classes %>"
+     id="comment-paragraph-plugin_<%= paragraph_uuid %>"
+     data-paragraph="<%= paragraph_uuid %>">
   <div class="comment_paragraph"><%= inner_html.html_safe %></div>
   <div class="side-comments-counter-container">
     <div class="side-comments-counter">


=====================================
test/unit/macro_test.rb
=====================================
--- a/test/unit/macro_test.rb
+++ b/test/unit/macro_test.rb
@@ -34,4 +34,10 @@ class MacroTest < ActiveSupport::TestCase
   should 'convert macro' do
     assert_equal 'Testing: It works!', macro.convert(macro_element, nil)
   end
+
+  should 'include element classes when parsing macro' do
+    macro.expects(:parse).with(has_entry('classes', 'macro nonEdit'),
+                               anything, anything)
+    macro.convert(macro_element, nil)
+  end
 end



View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/fe5052fce08746be8d108a33d5d1f1c7c0dc05f5...d0e9356f795832ac9e03dd5547fc15c581d58b27

---
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/fe5052fce08746be8d108a33d5d1f1c7c0dc05f5...d0e9356f795832ac9e03dd5547fc15c581d58b27
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20180323/56e52896/attachment-0001.html>


More information about the Noosfero-dev mailing list