class Ruhoh
Constants
- Root
- RuhohSpec
- Version
Attributes
log[RW]
root[R]
cache[R]
collections[R]
env[RW]
log[RW]
root[R]
routes[R]
Public Class Methods
collection(resource)
click to toggle source
# File lib/ruhoh.rb, line 173 def self.collection(resource) Collections.load(resource) end
model(resource)
click to toggle source
# File lib/ruhoh.rb, line 177 def self.model(resource) Collections.get_module_namespace_for(resource).const_get(:ModelView) end
new(opts={})
click to toggle source
# File lib/ruhoh.rb, line 46 def initialize(opts={}) self.class.log.log_file = opts[:log_file] if opts[:log_file] #todo @base = opts[:source] ? opts[:source] : Dir.getwd @collections = Ruhoh::Collections.new(self) @cache = Ruhoh::Cache.new(self) @routes = Ruhoh::Routes.new(self) end
Public Instance Methods
cascade()
click to toggle source
# File lib/ruhoh.rb, line 68 def cascade return @cascade if @cascade @cascade = Ruhoh::Cascade.new(config) @cascade.base = @base config.touch @cascade end
collection(resource)
click to toggle source
# File lib/ruhoh.rb, line 58 def collection(resource) @collections.load(resource) end
compile()
click to toggle source
Compile the ruhoh instance (save to disk). Note: This method recursively removes the target directory. Should there be a warning?
Extending:
TODO: Deprecate this functionality and come up with a 2.0-friendly interface. The Compiler module is a namespace for all compile "tasks". A "task" is a ruby Class that accepts @ruhoh instance via initialize. At compile time all classes in the Ruhoh::Compiler namespace are initialized and run. To add your own compile task simply namespace a class under Ruhoh::Compiler and provide initialize and run methods: class Ruhoh module Compiler class CustomTask def initialize(ruhoh) @ruhoh = ruhoh end def run # do something here end end end end
# File lib/ruhoh.rb, line 139 def compile Ruhoh::Friend.say { plain "Compiling for environment: '#{@env}'" } FileUtils.rm_r config['compiled_path'] if File.exist?(config['compiled_path']) FileUtils.mkdir_p config['compiled_path'] # Run the resource compilers compilers = @collections.all # Hack to ensure assets are processed first so post-processing logic reflects in the templates. compilers.delete('stylesheets') compilers.unshift('stylesheets') compilers.delete('javascripts') compilers.unshift('javascripts') compilers.each do |name| collection = collection(name) next unless collection.compiler? collection.load_compiler.run end # Run extra compiler tasks if available: if Ruhoh.const_defined?(:Compiler) Ruhoh::Compiler.constants.each {|c| compiler = Ruhoh::Compiler.const_get(c) next unless compiler.respond_to?(:new) task = compiler.new(self) next unless task.respond_to?(:run) task.run } end true end
compiled_path(url)
click to toggle source
# File lib/ruhoh.rb, line 94 def compiled_path(url) if config['compile_as_root'] url = url.gsub(/^#{ config.base_path.chomp('/') }\/?/, '') end path = File.expand_path(File.join(config['compiled_path'], url)).gsub(/\/{2,}/, '/') CGI.unescape(path) end
config()
click to toggle source
# File lib/ruhoh.rb, line 62 def config return @config if @config @config = Ruhoh::Config.new(self) @config.touch end
master_view(pointer)
click to toggle source
# File lib/ruhoh.rb, line 54 def master_view(pointer) Ruhoh::Views::MasterView.new(self, pointer) end
relative_path(filename)
click to toggle source
# File lib/ruhoh.rb, line 111 def relative_path(filename) filename.gsub(Regexp.new("^#{@base}/"), '') end
setup_plugins()
click to toggle source
# File lib/ruhoh.rb, line 78 def setup_plugins enable_sprockets = config['asset_pipeline']['enable'] rescue false if enable_sprockets Ruhoh::Friend.say { green "=> Oh boy! Asset pipeline enabled by way of sprockets =D" } sprockets = Dir[File.join(cascade.system, "plugins", "sprockets", "**/*.rb")] sprockets.each {|f| require f } end require 'ruhoh/plugins/local_plugins_plugin' Ruhoh::Plugins::Plugin.run_all self end
to_url(*args)
click to toggle source
Always remove trailing slash. Returns String - normalized url with prepended base_path
# File lib/ruhoh.rb, line 105 def to_url(*args) url = config.base_path + args.join('/') url = url.gsub(/\/{2,}/, '/') (url == "/") ? url : url.chomp('/') end