class Middleman::Extension::BemHtml

Public Class Methods

new(app, options_hash={}, &block) click to toggle source
Calls superclass method
# File lib/middleman-bem-html.rb, line 11
def initialize(app, options_hash={}, &block)
        super
end

Public Instance Methods

after_build() click to toggle source
# File lib/middleman-bem-html.rb, line 22
def after_build
        # This will work if you are building your CSS files in Middleman. If you are using an external_pipeline,
        # this after_build method will trigger before the external_pipeline. As such, you need to use PostCSS
        # and http://github.com/oncomouse/postcss-deadclass to remove all the cruft.

        # Set config[:internal_css] to false if you are using an external_pipeline and postcss-deadclass
        runInternalDeCrufter = app.config.internal_css.nil? ? true : app.config.internal_css
        if runInternalDeCrufter
                classesToKeep = app.config.classes_to_keep || []
                cssFiles = Dir.glob("#{app.config.build_dir}/#{app.config.css_dir}/**/*.css")
                htmlFiles = Dir.glob("#{app.config.build_dir}/**/*.html")
                
                css_deadfiles = CSSDeadClass.new({
                        html_files: htmlFiles,
                        css_files: cssFiles,
                        classes_to_keep: classesToKeep
                })
                css_deadfiles.parse
        end
end
ready() click to toggle source
# File lib/middleman-bem-html.rb, line 15
def ready
        # Setup Rack middleware to minify CSS
        app.use Rack, compressor: options[:compressor],
                                                                ignore: Array(options[:ignore]) + [/\.min\./],
                                                                inline_content_types: options[:inline_content_types]
end