class Rack::RackSeo::Base
Attributes
config[RW]
current_path[RW]
dispatcher[RW]
Public Class Methods
new(app, options, &block)
click to toggle source
# File lib/rack-seo/base.rb, line 8 def initialize app, options, &block @app = app if options[:config] @config = YAML.load(IO.read(options[:config])) else @config = YAML.load(IO.read("config/rack_seo.default.yml")) end end
Public Instance Methods
call(env)
click to toggle source
# File lib/rack-seo/base.rb, line 17 def call env # Setup document body ready to process status, headers, response = @app.call(env) return [status, headers, response] unless headers['Content-Type'] =~ /html/ body = ""; response.each do |part| body << part end document = Rack::RackSeo::Document.new(body) current_path = env['PATH_INFO'] || '/' execute!(document, current_path) body = document.to_html headers['Content-Length'] = body.length.to_s if headers['Content-Length'] # still UTF-8 unsafe [status, headers, [body]] end
execute!(document, current_path = '/')
click to toggle source
# File lib/rack-seo/base.rb, line 32 def execute!(document, current_path = '/') @dispatcher = RackSeo::Dispatcher.new(@config, current_path) set_meta_title(document, @dispatcher.title_format) set_meta_description(document, @dispatcher.description_selector) set_meta_keywords(document, @dispatcher.keywords_selector) end
set_meta_description(document, description_selector)
click to toggle source
# File lib/rack-seo/base.rb, line 45 def set_meta_description(document, description_selector) content = Rack::RackSeo::Summarizer.extract_description(document, description_selector) document.description_content = content end
set_meta_keywords(document, keywords_selector)
click to toggle source
# File lib/rack-seo/base.rb, line 50 def set_meta_keywords(document, keywords_selector) content = Rack::RackSeo::Summarizer.extract_keywords(document, keywords_selector) document.keywords_content = content end
set_meta_title(document, title_format)
click to toggle source
# File lib/rack-seo/base.rb, line 39 def set_meta_title(document, title_format) content = Rack::RackSeo::TitleFormatter.parse_meta_title(document, title_format) content = Rack::RackSeo::Sanitize.sanitize_meta_title(content) document.title_content = content end