Sha256: 23505afd44c7c8035138b123dcf8d9003be4a947de8e2aa8bdd1735c724f4d7c

Contents?: true

Size: 1.28 KB

Versions: 14

Compression:

Stored size: 1.28 KB

Contents

module Deface
  module TemplateHelper

    # used to find source for a partial or template using virtual_path
    def load_template_source(virtual_path, partial, apply_overrides=true)
      parts = virtual_path.split("/")
      prefix = []
      if parts.size == 2
        prefix << ""
        name = virtual_path
      else
        prefix << parts.shift
        name = parts.join("/")
      end

      #this needs to be reviewed for production mode, overrides not present
      Rails.application.config.deface.enabled = apply_overrides
      @lookup_context ||= ActionView::LookupContext.new(ActionController::Base.view_paths, {:formats => [:html]})
      view = @lookup_context.disable_cache do
        @lookup_context.find(name, prefix, partial)
      end

      if view.handler.to_s == "Haml::Plugin"
        Deface::HamlConverter.new(view.source).result
      elsif view.handler.class.to_s == "Slim::RailsTemplate"
        Deface::SlimConverter.new(view.source).result
      else
        view.source
      end
    end

    #gets source erb for an element
    def element_source(template_source, selector)
      doc = Deface::Parser.convert(template_source)

      doc.css(selector).inject([]) do |result, match|
        result << Deface::Parser.undo_erb_markup!(match.to_s.dup)
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
deface-1.6.2 lib/deface/template_helper.rb
deface-1.6.1 lib/deface/template_helper.rb
deface-1.6.0 lib/deface/template_helper.rb
deface-1.5.3 lib/deface/template_helper.rb
deface-1.5.2 lib/deface/template_helper.rb
deface-1.5.1 lib/deface/template_helper.rb
deface-1.5.0 lib/deface/template_helper.rb
deface-1.4.0 lib/deface/template_helper.rb
deface-1.3.2 lib/deface/template_helper.rb
deface-1.3.1 lib/deface/template_helper.rb
deface-1.3.0 lib/deface/template_helper.rb
deface-1.2.0 lib/deface/template_helper.rb
deface-1.1.0 lib/deface/template_helper.rb
deface-1.0.2 lib/deface/template_helper.rb