Sha256: afefab177cf44b79aa7ace153733fe1c09358b21ef9fd2a5ba13402b018163a6

Contents?: true

Size: 715 Bytes

Versions: 2

Compression:

Stored size: 715 Bytes

Contents

module HasWysiwygContent
  module TagHelper

    def wysiwyg(field, substitutions = {}, &block)
      block_captured = false
      field.to_s.gsub(/\{\{(.*?)\}\}/) do |match| 
        str = $1
        if str =~ /mailto\s*:\s*([^:\s]+)(?:\s*:\s*(.+))?/
          mail_to($1, $2, :encode => :javascript) 
        elsif str == 'yield' && block_given?
          block_captured = true
          capture(&block)
        else
          var, method = str.split('.', 2)
          substitutions.key?(var.to_sym) ? substitutions[var.to_sym].send(method) : match
        end
      end + ( block_given? && !block_captured ? capture(&block) : '' )
    end

  end
end

ActionView::Base.send :include, HasWysiwygContent::TagHelper

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
has_wysiwyg_content-0.0.2 lib/has_wysiwyg_content/action_view_helper.rb
has_wysiwyg_content-0.0.1 lib/has_wysiwyg_content/action_view_helper.rb