Sha256: a73f1a8bb840119820fc55f89d01799eb71be66aba76fb1a7b538fe19f9de1a2

Contents?: true

Size: 841 Bytes

Versions: 24

Compression:

Stored size: 841 Bytes

Contents

module Octopress
  module Ink
    module Tags
      class AssignTag < Liquid::Tag
        SYNTAX = /([[:word:]]+)\s*(=|\+=|\|\|=)\s*(.*)\s*/o

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

        def render(context)
          return unless markup = Helpers::Conditional.parse(@markup, context)

          if markup =~ SYNTAX
            var      = $1
            operator = $2
            value    = $3

            value = Helpers::Var.get_value(value, context)
            return if value.nil?

            context = Helpers::Var.set_var(var, operator, value, context)
          else
            raise SyntaxError.new("Syntax Error in 'assign tag': #{@markup} - Valid syntax: assign [var] = [source] | filter")
          end
          ''
        end
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
octopress-ink-1.0.0.alpha.35 lib/octopress-ink/tags/assign.rb
octopress-ink-1.0.0.alpha.34 lib/octopress-ink/tags/assign.rb
octopress-ink-1.0.0.alpha.33 lib/octopress-ink/tags/assign.rb
octopress-ink-1.0.0.alpha.32 lib/octopress-ink/tags/assign.rb