Class: Rack::RackSeo::Base
- Inherits:
-
Object
- Object
- Rack::RackSeo::Base
- Defined in:
- lib/rack-seo/base.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#current_path ⇒ Object
Returns the value of attribute current_path.
-
#dispatcher ⇒ Object
Returns the value of attribute dispatcher.
Instance Method Summary collapse
- #call(env) ⇒ Object
- #execute!(document, current_path = '/') ⇒ Object
-
#initialize(app, options, &block) ⇒ Base
constructor
A new instance of Base.
- #set_meta_description(document, description_selector) ⇒ Object
- #set_meta_keywords(document, keywords_selector) ⇒ Object
- #set_meta_title(document, title_format) ⇒ Object
Constructor Details
#initialize(app, options, &block) ⇒ Base
Returns a new instance of Base.
8 9 10 11 12 13 14 15 |
# File 'lib/rack-seo/base.rb', line 8 def initialize app, , &block @app = app if [:config] @config = YAML.load(IO.read([:config])) else @config = YAML.load(IO.read("config/rack_seo.default.yml")) end end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
4 5 6 |
# File 'lib/rack-seo/base.rb', line 4 def config @config end |
#current_path ⇒ Object
Returns the value of attribute current_path.
5 6 7 |
# File 'lib/rack-seo/base.rb', line 5 def current_path @current_path end |
#dispatcher ⇒ Object
Returns the value of attribute dispatcher.
6 7 8 |
# File 'lib/rack-seo/base.rb', line 6 def dispatcher @dispatcher end |
Instance Method Details
#call(env) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# 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 = '/') ⇒ Object
32 33 34 35 36 37 |
# File 'lib/rack-seo/base.rb', line 32 def execute!(document, current_path = '/') @dispatcher = RackSeo::Dispatcher.new(@config, current_path) (document, @dispatcher.title_format) (document, @dispatcher.description_selector) (document, @dispatcher.keywords_selector) end |
#set_meta_description(document, description_selector) ⇒ Object
45 46 47 48 |
# File 'lib/rack-seo/base.rb', line 45 def (document, description_selector) content = Rack::RackSeo::Summarizer.extract_description(document, description_selector) document.description_content = content end |
#set_meta_keywords(document, keywords_selector) ⇒ Object
50 51 52 53 |
# File 'lib/rack-seo/base.rb', line 50 def (document, keywords_selector) content = Rack::RackSeo::Summarizer.extract_keywords(document, keywords_selector) document.keywords_content = content end |