Module: Ro
- Extended by:
- Ro
- Included in:
- Ro
- Defined in:
- lib/ro.rb,
lib/ro.rb,
lib/ro/git.rb,
lib/ro/lock.rb,
lib/ro/node.rb,
lib/ro/root.rb,
lib/ro/slug.rb,
lib/ro/cache.rb,
lib/ro/model.rb,
lib/ro/template.rb,
lib/ro/node/list.rb,
lib/ro/blankslate.rb,
lib/ro/pagination.rb,
lib/ro/initializers/env.rb
Defined Under Namespace
Modules: Pagination Classes: BlankSlate, Cache, Git, Lock, Model, Node, Root, Slug, Template
Constant Summary collapse
- Version =
'1.4.6'
Class Method Summary collapse
- .absolute_path_for(*args) ⇒ Object
- .accurate_expand_asset_urls(html, node) ⇒ Object
- .debug! ⇒ Object
- .default_root ⇒ Object
- .erb(content, node = nil) ⇒ Object
- .expand_asset_urls(html, node) ⇒ Object
- .git ⇒ Object
- .log(*args, &block) ⇒ Object
- .md5(string) ⇒ Object
- .name_for(*args, &block) ⇒ Object
- .nodes(*args, &block) ⇒ Object
- .normalize_path(arg, *args) ⇒ Object
- .patch(*args, &block) ⇒ Object
- .paths_for(*args) ⇒ Object
- .query_string_for(hash, options = {}) ⇒ Object
- .realpath(path) ⇒ Object
- .relative_path(path, *args) ⇒ Object
- .relative_path_for(*args) ⇒ Object
- .render(*args, &block) ⇒ Object
- .render_source(*args, &block) ⇒ Object
- .root(*args) ⇒ Object
- .root=(root) ⇒ Object
- .sloppy_expand_asset_urls(html, node) ⇒ Object
- .slug_for(*args, &block) ⇒ Object
Instance Method Summary collapse
Class Method Details
.absolute_path_for(*args) ⇒ Object
250 251 252 253 |
# File 'lib/ro.rb', line 250 def Ro.absolute_path_for(*args) path = ('/' + paths_for(*args).join('/')).squeeze('/') path unless path.empty? end |
.accurate_expand_asset_urls(html, node) ⇒ Object
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/ro.rb', line 206 def Ro.(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! ⇒ Object
135 136 137 138 139 140 141 |
# File 'lib/ro.rb', line 135 def Ro.debug! @logger ||= ( logger = ::Logger.new(STDERR) logger.level = ::Logger::DEBUG logger ) end |
.default_root ⇒ Object
79 80 81 |
# File 'lib/ro.rb', line 79 def Ro.default_root [ ENV['RO_ROOT'], "./public/ro", "./source/ro" ].compact.detect{|d| test(?d, d)} || "./ro" end |
.erb(content, node = nil) ⇒ Object
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/ro.rb', line 174 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) ⇒ Object
198 199 200 201 202 203 204 |
# File 'lib/ro.rb', line 198 def Ro.(html, node) begin (html, node) rescue Object (html, node) end end |
.log(*args, &block) ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/ro.rb', line 143 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) ⇒ Object
131 132 133 |
# File 'lib/ro.rb', line 131 def Ro.md5(string) Digest::MD5.hexdigest(string) end |
.name_for(*args, &block) ⇒ Object
165 166 167 168 169 170 171 172 |
# File 'lib/ro.rb', line 165 def Ro.name_for(*args, &block) = Map.(args) unless .has_key?(:join) [:join] = '_' end args.push() Slug.for(*args, &block) end |
.nodes(*args, &block) ⇒ Object
116 117 118 |
# File 'lib/ro.rb', line 116 def Ro.nodes(*args, &block) root.nodes(*args, &block) end |
.normalize_path(arg, *args) ⇒ Object
260 261 262 |
# File 'lib/ro.rb', line 260 def Ro.normalize_path(arg, *args) absolute_path_for(arg, *args) end |
.patch(*args, &block) ⇒ Object
96 97 98 |
# File 'lib/ro.rb', line 96 def Ro.patch(*args, &block) git.patch(*args, &block) end |
.paths_for(*args) ⇒ Object
241 242 243 244 245 246 247 248 |
# File 'lib/ro.rb', line 241 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 = {}) ⇒ Object
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 |
# File 'lib/ro.rb', line 264 def Ro.query_string_for(hash, = {}) = Map.for() escape = .has_key?(:escape) ? [: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) ⇒ Object
127 128 129 |
# File 'lib/ro.rb', line 127 def Ro.realpath(path) Pathname.new(path.to_s).realpath end |
.relative_path(path, *args) ⇒ Object
120 121 122 123 124 125 |
# File 'lib/ro.rb', line 120 def Ro.relative_path(path, *args) = Map.(args) path = File.(String(path)) relative = File.(String(args.shift || [:relative] || [:to]) || [:from]) Pathname.new(path).relative_path_from(Pathname.new(relative)).to_s end |
.relative_path_for(*args) ⇒ Object
255 256 257 258 |
# File 'lib/ro.rb', line 255 def Ro.relative_path_for(*args) path = absolute_path_for(*args).sub(%r{^/+}, '') path unless path.empty? end |
.render(*args, &block) ⇒ Object
190 191 192 |
# File 'lib/ro.rb', line 190 def Ro.render(*args, &block) Template.render(*args, &block) end |
.render_source(*args, &block) ⇒ Object
194 195 196 |
# File 'lib/ro.rb', line 194 def Ro.render_source(*args, &block) Template.render_source(*args, &block) end |
.root(*args) ⇒ Object
87 88 89 90 |
# File 'lib/ro.rb', line 87 def Ro.root(*args) Ro.root = args.first unless args.empty? @root ||= Root.new(Ro.default_root) end |
.root=(root) ⇒ Object
83 84 85 |
# File 'lib/ro.rb', line 83 def Ro.root=(root) @root = Root.new(root.to_s) end |
.sloppy_expand_asset_urls(html, node) ⇒ Object
229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/ro.rb', line 229 def Ro.(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 |
Instance Method Details
#dependencies ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/ro.rb', line 19 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) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/ro.rb', line 33 def libdir(*args, &block) @libdir ||= File.(__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 |