class Decidim::EnhancedTextwork::ParagraphCreator
This class is responsible for creating the imported paragraphs and must be included in paragraphs component’s import manifest.
Attributes
context[R]
Public Class Methods
resource_klass()
click to toggle source
Retuns the resource class to be created with the provided data.
# File lib/decidim/enhanced_textwork/paragraph_creator.rb, line 9 def self.resource_klass Decidim::EnhancedTextwork::Paragraph end
Public Instance Methods
finish!()
click to toggle source
Saves the paragraph
Calls superclass method
# File lib/decidim/enhanced_textwork/paragraph_creator.rb, line 23 def finish! super # resource.save! notify(resource) publish(resource) end
produce()
click to toggle source
Produces a paragraph from parsed data
Returns a paragraph
# File lib/decidim/enhanced_textwork/paragraph_creator.rb, line 16 def produce resource.add_coauthor(context[:current_user], user_group: context[:user_group]) resource end
Private Instance Methods
available_locales()
click to toggle source
# File lib/decidim/enhanced_textwork/paragraph_creator.rb, line 62 def available_locales @available_locales ||= component.participatory_space.organization.available_locales end
body()
click to toggle source
# File lib/decidim/enhanced_textwork/paragraph_creator.rb, line 58 def body locale_hasher("body", available_locales) end
category()
click to toggle source
# File lib/decidim/enhanced_textwork/paragraph_creator.rb, line 44 def category id = data.has_key?(:category) ? data[:category]["id"] : data[:"category/id"].to_i Decidim::Category.find_by(id: id) end
component()
click to toggle source
# File lib/decidim/enhanced_textwork/paragraph_creator.rb, line 66 def component context[:current_component] end
notify(paragraph)
click to toggle source
# File lib/decidim/enhanced_textwork/paragraph_creator.rb, line 70 def notify(paragraph) return if paragraph.coauthorships.empty? Decidim::EventsManager.publish( event: "decidim.events.enhanced_textwork.paragraph_published", event_class: Decidim::EnhancedTextwork::PublishParagraphEvent, resource: paragraph, followers: coauthors_followers(paragraph) ) end
publish(paragraph)
click to toggle source
# File lib/decidim/enhanced_textwork/paragraph_creator.rb, line 81 def publish(paragraph) Decidim::EventsManager.publish( event: "decidim.events.enhanced_textwork.paragraph_published", event_class: Decidim::EnhancedTextwork::PublishParagraphEvent, resource: paragraph, followers: paragraph.participatory_space.followers - coauthors_followers(paragraph), extra: { participatory_space: true } ) end
resource()
click to toggle source
# File lib/decidim/enhanced_textwork/paragraph_creator.rb, line 33 def resource @resource ||= Decidim::EnhancedTextwork::Paragraph.new( category: category, scope: scope, title: title, body: body, component: component, published_at: Time.current ) end
scope()
click to toggle source
# File lib/decidim/enhanced_textwork/paragraph_creator.rb, line 49 def scope id = data.has_key?(:scope) ? data[:scope]["id"] : data[:"scope/id"].to_i Decidim::Scope.find_by(id: id) end
title()
click to toggle source
# File lib/decidim/enhanced_textwork/paragraph_creator.rb, line 54 def title locale_hasher("title", available_locales) end