Sha256: 954d4ab0a288ebb8d1dd70a3631b602a98a0c094355f50becb7b39b9bf0c9ec9

Contents?: true

Size: 1.16 KB

Versions: 1

Compression:

Stored size: 1.16 KB

Contents

module Bunto
  class Theme
    extend Forwardable
    attr_reader :name
    def_delegator :gemspec, :version, :version

    def initialize(name)
      @name = name.downcase.strip
      configure_sass
    end

    def root
      @root ||= gemspec.full_gem_path
    end

    def includes_path
      path_for :includes
    end

    def layouts_path
      path_for :layouts
    end

    def sass_path
      path_for :sass
    end

    def configure_sass
      return unless sass_path
      require 'sass'
      Sass.load_paths << sass_path
    end

    private

    def path_for(folder)
      resolved_dir = realpath_for(folder)
      return unless resolved_dir

      path = Bunto.sanitized_path(root, resolved_dir)
      path if Dir.exists?(path)
    end

    def realpath_for(folder)
      File.realpath(Bunto.sanitized_path(root, "_#{folder}"))
    rescue Errno::ENOENT, Errno::EACCES, Errno::ELOOP
      nil
    end

    def gemspec
      @gemspec ||= Gem::Specification.find_by_name(name)
    rescue Gem::LoadError
      raise Bunto::Errors::MissingDependencyException, "The #{name} theme could not be found."
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bunto-3.0.0 lib/bunto/theme.rb