Sha256: 7df6304f8f082c6ef359529f416ae9e90dfb6925dfb1fa7a8b5760dcbb9c0e35

Contents?: true

Size: 1.38 KB

Versions: 3

Compression:

Stored size: 1.38 KB

Contents

require 'active_support/core_ext/hash/keys'
require 'ostruct'
require 'yaml'

module Massimo
  class Config < OpenStruct
    DEFAULT_OPTIONS = {
      :source_path     => '.',
      :output_path     => 'public',
      :resources_path  => '.',
      :resources_url   => '/',
      :javascripts_url => '/javascripts',
      :stylesheets_url => '/stylesheets',
      :resources_url   => '/'
    }.freeze
    
    def initialize(options = nil)
      hash = DEFAULT_OPTIONS.dup
      
      options = YAML.load_file(options) if options.is_a?(String)
      hash.merge!(options.symbolize_keys) if options.is_a?(Hash)
      
      super hash
    end
    
    def source_path
      File.expand_path(super)
    end
    
    def output_path
      File.expand_path(super)
    end
    
    def path_for(resource_name)
      path_method = "#{resource_name}_path"
      if resource_path = (respond_to?(path_method) and send(path_method))
        File.expand_path(resource_path)
      else
        File.join(source_path, resource_name.to_s)
      end
    end
    
    def url_for(resource_name)
      url_method = "#{resource_name}_url"
      if resource_url = (respond_to?(url_method) and send(url_method))
        resource_url
      else
        resources_url
      end
    end
    
    def files_in(resource_name, extension = '*')
      Dir.glob(File.join(path_for(resource_name), "**/*.#{extension}"))
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
massimo-0.5.2 lib/massimo/config.rb
massimo-0.5.1 lib/massimo/config.rb
massimo-0.5.0 lib/massimo/config.rb