Sha256: 034af9adb607f67375e5aa4f9c288194c9e1c8e1886301d9f2262ef819cba360
Contents?: true
Size: 1.46 KB
Versions: 2
Compression:
Stored size: 1.46 KB
Contents
require 'pathname' module Staticpress module Helpers def config Staticpress::Configuration.instance end def extensionless_basename(pathname) extensionless_path(pathname).basename.to_s end def extensionless_path(pathname) pathname.sub(pathname.extname, '') end def hash_from_array(array, &block) reply = array.map do |object| [ block.call(object), object ] end Hash[reply] end def hash_from_match_data(match) Hash[match.names.map { |match_key| [match_key.to_sym, match[match_key]] }] end def paginate(range) reply = [] def reply.[](*args) super || [] end range_count = range.count per_page = config.posts_per_page array = range.to_a total_pages_count = (range_count / per_page) + ((range_count % per_page) == 0 ? 0 : 1) (0...total_pages_count).each do |number| reply << array[number * per_page, per_page] end reply end def settings Staticpress::Settings.instance end def spider_map(paths, &block) paths.map do |path| if path.directory? spider_map path.children, &block else block.call path end end end def titleize(url_path) url_path.sub(/^\//, '').split(/\//).map do |phrase| phrase.split(/-/).map(&:capitalize).join(config.title_separators.word) end.join(config.title_separators.phrase) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
staticpress-0.7.1 | lib/staticpress/helpers.rb |
staticpress-0.7.0 | lib/staticpress/helpers.rb |