Sha256: 6b6358efb1671ff31a7158e73f15602c5078ab2b260cf254d006a0482c3551d0

Contents?: true

Size: 1.23 KB

Versions: 1

Compression:

Stored size: 1.23 KB

Contents

module Octopress
  module Multilingual
    class SiteHook < Hooks::Site
      priority :high
      # Generate site_payload so other plugins can access
      def post_read(site)
        Octopress::Multilingual.site = site
        site.config['languages'] = site.languages
      end

      def pre_render(site)

        # Add translation page data to each page or post.
        #
        [site.pages, site.posts].flatten.each do |item|
          if item.translated
            # Access array of translated items via (post/page).translations
            item.data.merge!({
              'translations' => item.translations,
              'translated' => item.translated
            })
          end
        end
      end

      def merge_payload(payload, site)
        Octopress::Multilingual.site_payload
      end
    end

    class PagePayloadHook < Hooks::All
      priority :high

      def post_init(item)
        if item.lang == 'default'
          item.data['lang'] = item.site.config['lang']
        end
      end

      # Swap out post arrays with posts of the approrpiate language
      #
      def merge_payload(payload, item)
        if item.lang
          Octopress::Multilingual.page_payload(item.lang)
        end
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
octopress-multilingual-0.3.0 lib/octopress-multilingual/hooks.rb