class Genit::Css

Deals with the styles directory.

Public Class Methods

new(working_dir) click to toggle source

Public: Constructor.

working_dir - The String working directory, where live the project.

# File lib/genit/project/css.rb, line 12
def initialize working_dir
  @working_dir = working_dir
end

Public Instance Methods

render() click to toggle source

Public: Render css in the styles directory.

Returns nothing.

# File lib/genit/project/css.rb, line 19
def render
  Dir.glob(File.join(@working_dir, STYLES_DIR, '**/*')) do |filename|
    @filename = filename
    if @filename.end_with?(".sass")
      render_sass :sass
    elsif @filename.end_with?(".scss")
      render_sass :scss
    end
  end
end

Private Instance Methods

render_sass(type) click to toggle source

Render css from sass in the styles directory.

type - A Symbol for the sass syntax, either :sass or :scss.

Returns nothing.

# File lib/genit/project/css.rb, line 37
def render_sass type
  template = File.open(@filename).read
  begin
    css = Sass::Engine.new(template, syntax: type).render
  rescue Exception => ex
    error "In #{@filename}\n  #{ex}"
  end
  @filename.gsub!(/(sass|scss)$/, 'css')
  File.open(@filename, "w") {|out| out.puts css }
end