class Trekky::Context

Attributes

source_dir[R]

Public Class Methods

new(source_dir) click to toggle source
# File lib/trekky/context.rb, line 10
def initialize(source_dir)
  @source_dir = source_dir
  @files = { layouts: [], partials: [], sources: [] }
  build
end

Public Instance Methods

find_partial(name) click to toggle source
# File lib/trekky/context.rb, line 28
def find_partial(name)
  partials.find {|p| p.path == File.join(source_dir, name)}
end
layouts() click to toggle source
# File lib/trekky/context.rb, line 24
def layouts
  @files[:layouts]
end
partials() click to toggle source
# File lib/trekky/context.rb, line 20
def partials
  @files[:partials]
end
sources() click to toggle source
# File lib/trekky/context.rb, line 16
def sources
  @files[:sources]
end

Private Instance Methods

build() click to toggle source
# File lib/trekky/context.rb, line 34
def build
  Dir.glob(File.join(source_dir, "**/*")).each do |path|

    next if File.directory?(path)

    source = build_source(path)

    if path.include?("#{source_dir}/layouts")
      @files[:layouts] << source
      next
    end

    if File.basename(path)[0] == '_'
      @files[:partials] << source
      next
    end

    @files[:sources] << source
  end
end
build_source(path) click to toggle source
# File lib/trekky/context.rb, line 55
def build_source(path)
  type = File.extname(path)[1..-1].intern
  find_source_class(type).new(self, path)
end
find_source_class(type) click to toggle source
# File lib/trekky/context.rb, line 60
def find_source_class(type)
  types[type] || StaticSource
end
types() click to toggle source
# File lib/trekky/context.rb, line 64
def types
  { sass: SassSource, haml: HamlSource }
end