Module: Staticpress::Helpers
- Included in:
- CLI, Content::Base, Content::Base, Plugin, Pusher, Pusher, Route, Site, Theme, Theme, ViewHelpers
- Defined in:
- lib/staticpress/helpers.rb
Instance Method Summary collapse
- #config ⇒ Object
- #extensionless_basename(pathname) ⇒ Object
- #extensionless_path(pathname) ⇒ Object
- #hash_from_array(array, &block) ⇒ Object
- #hash_from_match_data(match) ⇒ Object
- #paginate(range) ⇒ Object
- #settings ⇒ Object
- #spider_map(paths, &block) ⇒ Object
- #titleize(url_path) ⇒ Object
Instance Method Details
#config ⇒ Object
5 6 7 |
# File 'lib/staticpress/helpers.rb', line 5 def config Staticpress::Configuration.instance end |
#extensionless_basename(pathname) ⇒ Object
9 10 11 |
# File 'lib/staticpress/helpers.rb', line 9 def extensionless_basename(pathname) extensionless_path(pathname).basename.to_s end |
#extensionless_path(pathname) ⇒ Object
13 14 15 |
# File 'lib/staticpress/helpers.rb', line 13 def extensionless_path(pathname) pathname.sub(pathname.extname, '') end |
#hash_from_array(array, &block) ⇒ Object
17 18 19 20 21 22 23 |
# 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) ⇒ Object
25 26 27 |
# 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) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# 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 ⇒ Object
48 49 50 |
# File 'lib/staticpress/helpers.rb', line 48 def settings Staticpress::Settings.instance end |
#spider_map(paths, &block) ⇒ Object
52 53 54 55 56 57 58 59 60 |
# 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) ⇒ Object
62 63 64 65 66 |
# 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 |