module Staticpress::Helpers
Public Instance Methods
config()
click to toggle source
# File lib/staticpress/helpers.rb, line 5 def config Staticpress::Configuration.instance end
extensionless_basename(pathname)
click to toggle source
# File lib/staticpress/helpers.rb, line 9 def extensionless_basename(pathname) extensionless_path(pathname).basename.to_s end
extensionless_path(pathname)
click to toggle source
# File lib/staticpress/helpers.rb, line 13 def extensionless_path(pathname) pathname.sub(pathname.extname, '') end
hash_from_array(array, &block)
click to toggle source
# File lib/staticpress/helpers.rb, line 17 def hash_from_array(array, &block) reply = array.map do |object| [ block.call(object), object ] end Hash[reply] end
hash_from_match_data(match)
click to toggle source
# File lib/staticpress/helpers.rb, line 25 def hash_from_match_data(match) Hash[match.names.map { |match_key| [match_key.to_sym, match[match_key]] }] end
paginate(range)
click to toggle source
# File lib/staticpress/helpers.rb, line 29 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
settings()
click to toggle source
# File lib/staticpress/helpers.rb, line 48 def settings Staticpress::Settings.instance end
spider_map(paths, &block)
click to toggle source
# File lib/staticpress/helpers.rb, line 52 def spider_map(paths, &block) paths.map do |path| if path.directory? spider_map path.children, &block else block.call path end end end
titleize(url_path)
click to toggle source
# File lib/staticpress/helpers.rb, line 62 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