Sha256: 953f86ecb2733dab8d26a4d42e0c0dc9f2613ed7cfa97cd3c200c96029d00c58

Contents?: true

Size: 1.74 KB

Versions: 2

Compression:

Stored size: 1.74 KB

Contents

require 'digest/md5'

module Gumdrop
  
  module Util
    module ViewHelpers
      
      def hidden(&block)
        #no-op
      end

      def urlencode(string)
        require "erb" unless defined? ERB
        ERB::Util.url_encode(string)
      end
      
      def markdown(source)
        eng_class= Gumdrop::Renderer.for 'markdown'
        unless eng_class.nil?
          eng= eng_class.new { source }
          eng.render
        else
          raise StandardError, "Markdown is not available: Include a Markdown engine in your Gemfile!"
        end
      end
      
      def textile(source)
        eng_class= Gumdrop::Renderer.for 'textile'
        unless eng_class.nil?
          eng= eng_class.new { source }
          eng.render
        else
          raise StandardError, "Textile is not available: Include a Textile engine in your Gemfile!"
        end
      end

      def uri_fresh(path)
        if (path[0] == '/')
          internal_path= path[1..-1]
        else
          internal_path= path
          path= "/#{path}"
        end
        "#{ path }?v=#{ checksum_for internal_path }"
      end

      def cache_bust(path)
        uri_fresh(path)
      end

      def checksum_for(path)
        path= path[1..-1] if path[0] == '/'
        @_checksum_cache ||= {}
        if @_checksum_cache.has_key? path
          @_checksum_cache[path]
        else
          content= render path
          @_checksum_cache[path]= Digest::MD5.hexdigest( content )
        end
      end
      
      def config
        site.config
      end

      def data
        site.data
      end

      def gumdrop_version
        ::Gumdrop::VERSION
      end
      
    end
  end
  
  class << self

    def view_helpers(&block)
      Util::ViewHelpers.class_eval &block
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
gumdrop-1.1.3 lib/gumdrop/util/view_helpers.rb
gumdrop-1.1.2 lib/gumdrop/util/view_helpers.rb