Sha256: b8760846f4a2aa503aefeeee12d535dafb441212cbe5c884736029ffbf371faa

Contents?: true

Size: 1.23 KB

Versions: 41

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true

module Decidim
  module System
    # A command with all the business logic when creating a new organization in
    # the system. It creates the organization and invites the admin to the
    # system.
    class CreateDefaultPages < Rectify::Command
      # Public: Initializes the command.
      #
      # form - A form object with the params.
      def initialize(organization)
        @organization = organization
      end

      # Executes the command.
      #
      # Returns nothing.
      def call
        Decidim::StaticPage::DEFAULT_PAGES.map do |slug|
          Decidim::StaticPage.find_or_create_by!(slug: slug) do |page|
            page.organization = organization
            page.title = localized_attribute(slug, :title)
            page.content = localized_attribute(slug, :content)
          end
        end
      end

      private

      attr_reader :organization

      def localized_attribute(slug, attribute)
        Decidim.available_locales.inject({}) do |result, locale|
          text = I18n.with_locale(locale) do
            I18n.t(attribute, scope: "decidim.system.default_pages.placeholders", page: slug)
          end

          result.update(locale => text)
        end
      end
    end
  end
end

Version data entries

41 entries across 41 versions & 2 rubygems

Version Path
decidim-0.6.8 decidim-system/app/commands/decidim/system/create_default_pages.rb
decidim-system-0.6.7 app/commands/decidim/system/create_default_pages.rb
decidim-0.6.7 decidim-system/app/commands/decidim/system/create_default_pages.rb
decidim-system-0.6.6 app/commands/decidim/system/create_default_pages.rb
decidim-0.6.6 decidim-system/app/commands/decidim/system/create_default_pages.rb
decidim-system-0.6.5 app/commands/decidim/system/create_default_pages.rb
decidim-0.6.5 decidim-system/app/commands/decidim/system/create_default_pages.rb
decidim-system-0.6.4 app/commands/decidim/system/create_default_pages.rb
decidim-0.6.4 decidim-system/app/commands/decidim/system/create_default_pages.rb
decidim-system-0.6.3 app/commands/decidim/system/create_default_pages.rb
decidim-0.6.3 decidim-system/app/commands/decidim/system/create_default_pages.rb
decidim-system-0.6.2 app/commands/decidim/system/create_default_pages.rb
decidim-0.6.2 decidim-system/app/commands/decidim/system/create_default_pages.rb
decidim-system-0.6.1 app/commands/decidim/system/create_default_pages.rb
decidim-0.6.1 decidim-system/app/commands/decidim/system/create_default_pages.rb
decidim-system-0.6.0 app/commands/decidim/system/create_default_pages.rb
decidim-0.6.0 decidim-system/app/commands/decidim/system/create_default_pages.rb
decidim-system-0.5.1 app/commands/decidim/system/create_default_pages.rb
decidim-0.5.1 decidim-system/app/commands/decidim/system/create_default_pages.rb
decidim-system-0.5.0 app/commands/decidim/system/create_default_pages.rb