Sha256: 00509158ce0828940734e8357cf324a38ef73c633c9f8f2bad506520ba364e83

Contents?: true

Size: 1.63 KB

Versions: 24

Compression:

Stored size: 1.63 KB

Contents

module Octopress
  module Ink
    module Tags
      class IncludeTag < Liquid::Tag
        PLUGIN_SYNTAX = /(.+?):(\S+)/

        def initialize(tag_name, markup, tokens)
          super
          @og_markup = @markup = markup
        end

        def render(context)
          return unless markup = Helpers::Conditional.parse(@markup, context)
          if markup =~ Helpers::Var::HAS_FILTERS
            markup = $1
            filters = $2
          end
          markup = Helpers::Var.evaluate_ternary(markup, context)
          markup = Helpers::Path.parse(markup, context)

          include_tag = Jekyll::Tags::IncludeTag.new('include', markup, [])

          # If markup references a plugin e.g. plugin-name:include-file.html
          if markup.strip =~ PLUGIN_SYNTAX
            plugin = $1
            path = $2
            begin
              content = Plugins.include(plugin, path).read
            rescue => error
              raise IOError.new "Include failed: {% #{@tag_name} #{@og_markup}%}. The plugin '#{plugin}' does not have an include named '#{path}'."
            end
            partial = Liquid::Template.parse(content)
            content = context.stack {
              context['include'] = include_tag.parse_params(context)
              partial.render!(context)
            }.strip
            
          # Otherwise, use Jekyll's default include tag
          else
            content = include_tag.render(context).strip
          end

          unless content.nil? || filters.nil?
            content = Helpers::Var.render_filters(content, filters, context)
          end

          content
        end
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
octopress-ink-1.0.0.rc.11 lib/octopress-ink/tags/include.rb
octopress-ink-1.0.0.rc.10 lib/octopress-ink/tags/include.rb
octopress-ink-1.0.0.rc.9 lib/octopress-ink/tags/include.rb
octopress-ink-1.0.0.rc.8 lib/octopress-ink/tags/include.rb
octopress-ink-1.0.0.rc.7 lib/octopress-ink/tags/include.rb
octopress-ink-1.0.0.rc.6 lib/octopress-ink/tags/include.rb
octopress-ink-1.0.0.rc.5 lib/octopress-ink/tags/include.rb
octopress-ink-1.0.0.rc.3 lib/octopress-ink/tags/include.rb
octopress-ink-1.0.0.rc.2 lib/octopress-ink/tags/include.rb
octopress-ink-1.0.0.rc.1 lib/octopress-ink/tags/include.rb
octopress-ink-1.0.0.alpha.45 lib/octopress-ink/tags/include.rb
octopress-ink-1.0.0.alpha.44 lib/octopress-ink/tags/include.rb
octopress-ink-1.0.0.alpha.43 lib/octopress-ink/tags/include.rb
octopress-ink-1.0.0.alpha.42 lib/octopress-ink/tags/include.rb
octopress-ink-1.0.0.alpha.41 lib/octopress-ink/tags/include.rb
octopress-ink-1.0.0.alpha.40 lib/octopress-ink/tags/include.rb
octopress-ink-1.0.0.alpha.39 lib/octopress-ink/tags/include.rb
octopress-ink-1.0.0.alpha.38 lib/octopress-ink/tags/include.rb
octopress-ink-1.0.0.alpha.37 lib/octopress-ink/tags/include.rb
octopress-ink-1.0.0.alpha.36 lib/octopress-ink/tags/include.rb