Sha256: 1bebc4179a0a8017c0954b74374e66f89afb1e0e80df1ad29377f84508d7b975

Contents?: true

Size: 1.13 KB

Versions: 1

Compression:

Stored size: 1.13 KB

Contents

require 'rails/generators'

module Revelry
  module Generators
    module Content
      class CssGenerator < ::Rails::Generators::Base
        CSS_FILE_EXTENSIONS = %w(
          .css
          .css.sass
          .css.scss
          .sass
          .scss
        )

        def add_css_assets
          if using_sass?
            append_to_file css_app_bundle do
              '@import "revelry_content";'
            end
          else
            insert_into_file css_app_bundle, before: %r{(//|\*)= require_self} do
              "*= require revelry_content\n "
            end
          end
        end

        private

        def using_sass?
          /s(c|a)ss/.match(css_file_extname)
        end

        def css_app_bundle
          File.join(css_base_dir, "revelry-app#{ css_file_extname }")
        end

        def css_base_dir
          File.join('app', 'assets', 'stylesheets')
        end

        def test_css_format(fmt)
          File.exist?(File.join(css_base_dir, "revelry-app#{ fmt }"))
        end

        def css_file_extname
          CSS_FILE_EXTENSIONS.find { |fmt| test_css_format(fmt) }
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
revelry_content-1.0.0 lib/generators/revelry/content/css_generator.rb