Class: Multigiri
- Inherits:
-
Object
- Object
- Multigiri
- Defined in:
- lib/multigiri.rb,
lib/multigiri/html5.rb,
lib/multigiri/minify.rb,
lib/multigiri/version.rb,
lib/multigiri/link_checker.rb,
lib/multigiri/email_obfuscator.rb,
lib/multigiri/google_analytics.rb,
lib/multigiri/default_attributes.rb
Overview
Defined Under Namespace
Modules: HTML5 Classes: DefaultAttributes, EmailObfuscator, GoogleAnalytics, LinkChecker, Minify
Constant Summary collapse
- VERSION =
"0.0.4"
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = Hash.new, &block) ⇒ Multigiri
constructor
A new instance of Multigiri.
-
#use(klass, *args, &block) ⇒ Object
GoogleAnalytics.new(Other.new(self), tracking_code).
Constructor Details
#initialize(app, options = Hash.new, &block) ⇒ Multigiri
Returns a new instance of Multigiri.
15 16 17 18 |
# File 'lib/multigiri.rb', line 15 def initialize(app, = Hash.new, &block) @app, @options, @block = app, , block @options[:indentation] ||= 2 end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
14 15 16 |
# File 'lib/multigiri.rb', line 14 def block @block end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
14 15 16 |
# File 'lib/multigiri.rb', line 14 def @options end |
Instance Method Details
#call(env) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/multigiri.rb', line 20 def call(env) # convert to a Nokogiri document status, headers, chunks = @app.call(env) # the only what we know about body is that it has to respond to #each body = String.new chunks.each { |chunk| body += chunk } document = Nokogiri::HTML(body) # before @stack = lambda { |env| [status, headers, document] } # get middlewares self.instance_eval(&@block) if @block # convert back to a [String] status, headers, document = @stack.call(env) body = document.to_html(indentation: [:indentation]) # TODO headers["Content-Length"] = body.bytesize.to_s [status, headers, [body]] end |
#use(klass, *args, &block) ⇒ Object
GoogleAnalytics.new(Other.new(self), tracking_code)
40 41 42 |
# File 'lib/multigiri.rb', line 40 def use(klass, *args, &block) @stack = klass.new(@stack, *args, &block) end |