Class: Middleman::AsciiDoc::DefaultLayoutConfigurator

Inherits:
Object
  • Object
show all
Defined in:
lib/middleman-asciidoc/extension.rb

Overview

Resolves the automatic layout if no layout has been specified and this resource is not a blog article

Instance Method Summary collapse

Constructor Details

#initialize(app, layout) ⇒ DefaultLayoutConfigurator

Returns a new instance of DefaultLayoutConfigurator.


316
317
318
319
# File 'lib/middleman-asciidoc/extension.rb', line 316

def initialize app, layout
  @app = app
  @layout = layout
end

Instance Method Details

#asciidoc_file?(resource) ⇒ Boolean

Returns:

  • (Boolean)

338
339
340
# File 'lib/middleman-asciidoc/extension.rb', line 338

def asciidoc_file? resource
  (path = resource.source_file) && (path.end_with? *@app.config[:asciidoc_extensions])
end

#blog_article?(resource) ⇒ Boolean

Returns:

  • (Boolean)

342
343
344
# File 'lib/middleman-asciidoc/extension.rb', line 342

def blog_article? resource
  resource.respond_to? :blog_data
end

#has_auto_layout?(resource) ⇒ Boolean

Returns:

  • (Boolean)

334
335
336
# File 'lib/middleman-asciidoc/extension.rb', line 334

def has_auto_layout? resource
  resource.options[:layout] == :_auto_layout
end

#manipulate_resource_list(resources) ⇒ Object


321
322
323
324
325
326
327
328
329
330
331
332
# File 'lib/middleman-asciidoc/extension.rb', line 321

def manipulate_resource_list resources
  resources.select {|res| !res.ignored? && (has_auto_layout? res) && (asciidoc_file? res) }.each do |resource|
    if (blog_article? resource) &&
        (blog_layout = resource.blog_data.options[:layout]) &&
        (blog_layout = blog_layout.to_sym) != :_auto_layout
      resource.options[:layout] = blog_layout
    else
      resource.options[:layout] = @layout
    end
  end
  resources
end