module Ro
Constants
- Version
Public Class Methods
absolute_path_for(*args)
click to toggle source
# File lib/ro.rb, line 249 def Ro.absolute_path_for(*args) path = ('/' + paths_for(*args).join('/')).squeeze('/') path unless path.empty? end
accurate_expand_asset_urls(html, node)
click to toggle source
# File lib/ro.rb, line 205 def Ro.accurate_expand_asset_urls(html, node) doc = Nokogiri::HTML.fragment(html) doc.traverse do |element| if element.respond_to?(:attributes) element.attributes.each do |attr, attribute| value = attribute.value if value =~ %r{(?:./)?assets/(.+)$} begin base, ext = $1.split('.', 2) url = node.url_for(base) attribute.value = url rescue Object next end end end end end doc.to_s.strip end
debug!()
click to toggle source
# File lib/ro.rb, line 134 def Ro.debug! @logger ||= ( logger = ::Logger.new(STDERR) logger.level = ::Logger::DEBUG logger ) end
default_root()
click to toggle source
# File lib/ro.rb, line 78 def Ro.default_root [ ENV['RO_ROOT'], "./public/ro", "./source/ro" ].compact.detect{|d| test(?d, d)} || "./ro" end
erb(content, node = nil)
click to toggle source
# File lib/ro.rb, line 173 def Ro.erb(content, node = nil) binding = case node when Binding node when Node node._binding when nil nil else instance_eval{ Kernel.binding } end ERB.new(content.to_s).result(binding) end
expand_asset_urls(html, node)
click to toggle source
# File lib/ro.rb, line 197 def Ro.expand_asset_urls(html, node) begin accurate_expand_asset_urls(html, node) rescue Object sloppy_expand_asset_urls(html, node) end end
git()
click to toggle source
# File lib/ro.rb, line 91 def Ro.git root.git end
log(*args, &block)
click to toggle source
# File lib/ro.rb, line 142 def Ro.log(*args, &block) return if @logger.nil? level = if args.size == 1 :debug else args.shift end @logger.send(level, *args, &block) end
md5(string)
click to toggle source
# File lib/ro.rb, line 130 def Ro.md5(string) Digest::MD5.hexdigest(string) end
name_for(*args, &block)
click to toggle source
# File lib/ro.rb, line 164 def Ro.name_for(*args, &block) options = Map.options_for!(args) unless options.has_key?(:join) options[:join] = '_' end args.push(options) Slug.for(*args, &block) end
nodes(*args, &block)
click to toggle source
# File lib/ro.rb, line 115 def Ro.nodes(*args, &block) root.nodes(*args, &block) end
normalize_path(arg, *args)
click to toggle source
# File lib/ro.rb, line 259 def Ro.normalize_path(arg, *args) absolute_path_for(arg, *args) end
patch(*args, &block)
click to toggle source
# File lib/ro.rb, line 95 def Ro.patch(*args, &block) git.patch(*args, &block) end
paths_for(*args)
click to toggle source
# File lib/ro.rb, line 240 def Ro.paths_for(*args) path = args.flatten.compact.join('/') path.gsub!(%r|[.]+/|, '/') path.squeeze!('/') path.sub!(%r|^/|, '') path.sub!(%r|/$|, '') paths = path.split('/') end
query_string_for(hash, options = {})
click to toggle source
# File lib/ro.rb, line 263 def Ro.query_string_for(hash, options = {}) options = Map.for(options) escape = options.has_key?(:escape) ? options[:escape] : true pairs = [] esc = escape ? proc{|v| CGI.escape(v.to_s)} : proc{|v| v.to_s} hash.each do |key, values| key = key.to_s values = [values].flatten values.each do |value| value = value.to_s if value.empty? pairs << [ esc[key] ] else pairs << [ esc[key], esc[value] ].join('=') end end end pairs.replace pairs.sort_by{|pair| pair.size} pairs.join('&') end
realpath(path)
click to toggle source
# File lib/ro.rb, line 126 def Ro.realpath(path) Pathname.new(path.to_s).realpath end
relative_path(path, *args)
click to toggle source
# File lib/ro.rb, line 119 def Ro.relative_path(path, *args) options = Map.options_for!(args) path = File.expand_path(String(path)) relative = File.expand_path(String(args.shift || options[:relative] || options[:to]) || options[:from]) Pathname.new(path).relative_path_from(Pathname.new(relative)).to_s end
relative_path_for(*args)
click to toggle source
# File lib/ro.rb, line 254 def Ro.relative_path_for(*args) path = absolute_path_for(*args).sub(%r{^/+}, '') path unless path.empty? end
render(*args, &block)
click to toggle source
# File lib/ro.rb, line 189 def Ro.render(*args, &block) Template.render(*args, &block) end
render_source(*args, &block)
click to toggle source
# File lib/ro.rb, line 193 def Ro.render_source(*args, &block) Template.render_source(*args, &block) end
root(*args)
click to toggle source
# File lib/ro.rb, line 86 def Ro.root(*args) Ro.root = args.first unless args.empty? @root ||= Root.new(Ro.default_root) end
root=(root)
click to toggle source
# File lib/ro.rb, line 82 def Ro.root=(root) @root = Root.new(root.to_s) end
sloppy_expand_asset_urls(html, node)
click to toggle source
# File lib/ro.rb, line 228 def Ro.sloppy_expand_asset_urls(html, node) html.to_s.gsub(%r{['"]assets/([^'"]+)['"]}) do |match| base, ext = $1.split('.', 2) begin node.url_for(base).inspect rescue Object match end end end
slug_for(*args, &block)
click to toggle source
# File lib/ro.rb, line 155 def Ro.slug_for(*args, &block) options = Map.options_for!(args) unless options.has_key?(:join) options[:join] = '-' end args.push(options) Slug.for(*args, &block) end
Public Instance Methods
dependencies()
click to toggle source
# File lib/ro.rb, line 18 def dependencies { 'map' => [ 'map' , ' >= 6.5.1' ] , 'fattr' => [ 'fattr' , ' >= 2.2.1' ] , 'tilt' => [ 'tilt' , ' >= 1.3.1' ] , 'pygments' => [ 'pygments.rb' , ' >= 0.5.0' ] , 'coerce' => [ 'coerce' , ' >= 0.0.4' ] , 'stringex' => [ 'stringex' , ' >= 2.1.0' ] , 'systemu' => [ 'systemu' , ' >= 2.5.2' ] , 'nokogiri' => [ 'nokogiri' , ' >= 1.6.1' ] , 'main' => [ 'main' , ' >= 5.2.0' ] , } end
libdir(*args, &block)
click to toggle source
# File lib/ro.rb, line 32 def libdir(*args, &block) @libdir ||= File.expand_path(__FILE__).sub(/\.rb$/,'') args.empty? ? @libdir : File.join(@libdir, *args) ensure if block begin $LOAD_PATH.unshift(@libdir) block.call() ensure $LOAD_PATH.shift() end end end
load(*libs)
click to toggle source
# File lib/ro.rb, line 46 def load(*libs) libs = libs.join(' ').scan(/[^\s+]+/) Ro.libdir{ libs.each{|lib| Kernel.load(lib) } } end
version()
click to toggle source
# File lib/ro.rb, line 14 def version Ro::Version end