class EditModeRails::AutoInclude::Filter
Constants
- CLOSING_BODY_TAG
Attributes
controller[R]
Public Class Methods
filter(controller)
click to toggle source
# File lib/editmode-rails/auto_include_filter.rb, line 14 def self.filter(controller) auto_include_filter = new(controller) return unless auto_include_filter.include_javascript? auto_include_filter.include_javascript! end
new(kontroller)
click to toggle source
# File lib/editmode-rails/auto_include_filter.rb, line 23 def initialize(kontroller) @controller = kontroller end
Public Instance Methods
include_javascript!()
click to toggle source
# File lib/editmode-rails/auto_include_filter.rb, line 27 def include_javascript! response.body = response.body.gsub(CLOSING_BODY_TAG, editmode_script_tag.output + '\\0') end
include_javascript?()
click to toggle source
# File lib/editmode-rails/auto_include_filter.rb, line 31 def include_javascript? enabled_for_environment? && html_content_type? && response_has_closing_body_tag? && editmode_script_tag.valid? end
Private Instance Methods
editmode_script_tag()
click to toggle source
# File lib/editmode-rails/auto_include_filter.rb, line 51 def editmode_script_tag @script_tag ||= EditModeRails::ScriptTag.new() end
enabled_for_environment?()
click to toggle source
# File lib/editmode-rails/auto_include_filter.rb, line 55 def enabled_for_environment? enabled_environments = ["production","development","staging"] return true if enabled_environments.nil? enabled_environments.map(&:to_s).include?(Rails.env) end
html_content_type?()
click to toggle source
# File lib/editmode-rails/auto_include_filter.rb, line 43 def html_content_type? response.content_type == 'text/html' end
response()
click to toggle source
# File lib/editmode-rails/auto_include_filter.rb, line 39 def response controller.response end
response_has_closing_body_tag?()
click to toggle source
# File lib/editmode-rails/auto_include_filter.rb, line 47 def response_has_closing_body_tag? !!(response.body[CLOSING_BODY_TAG]) end