class Artifact::Middleman
Constants
- POST_EXTENSION
Private Instance Methods
check_post_meta!(action)
click to toggle source
# File lib/artifact/middleman.rb, line 191 def check_post_meta!(action) meta = (params[:meta] || {}).symbolize_keys.merge(:last_updated_by => current_user[:email]) if !meta[:date] or action.to_s.downcase.to_sym == :publish meta[:date] = Time.now.utc.strftime("%Y-%m-%d %H:%M %Z") else # puts "Meta date is #{meta[:date]}" return false unless valid_date?(meta[:date]) end meta[:author] = current_user[:name] unless meta[:author] meta end
filter_and_sort(posts, criteria)
click to toggle source
# File lib/artifact/middleman.rb, line 213 def filter_and_sort(posts, criteria) posts.select { |f| f.is_a?(WritableFile) }.sort do |a,b| b.send(criteria) <=> a.send(criteria) end end
get_uploads()
click to toggle source
# File lib/artifact/middleman.rb, line 209 def get_uploads @uploads = Artifact.uploads.all.last(10).reverse end
publish_post!(post)
click to toggle source
# File lib/artifact/middleman.rb, line 219 def publish_post!(post) filename = post.title.parameterize new_file = Artifact.posts.new(filename, POST_EXTENSION) Artifact.repo.move(post.path, new_file.path, current_user) end
rebuild!()
click to toggle source
# File lib/artifact/middleman.rb, line 231 def rebuild! puts `bundle exec middleman build #{Artifact.config.rebuild_args}` end
unpublish_post!(post)
click to toggle source
# File lib/artifact/middleman.rb, line 225 def unpublish_post!(post) filename = post.title.parameterize new_file = Artifact.drafts.new(filename, POST_EXTENSION) Artifact.repo.move(post.path, new_file.path, current_user) end
updated!()
click to toggle source
# File lib/artifact/middleman.rb, line 235 def updated! return if Artifact.middleman.nil? # not loaded yet! # set environment to build so the whole app doesn't get reloaded # for each file inside the reload_path block # ref: https://github.com/middleman/middleman/blob/v3-stable/middleman-core/lib/middleman-core/sitemap/extensions/on_disk.rb#L62 Artifact.middleman.config[:environment] = :build puts "Reloading Middleman..." Artifact.middleman.files.reload_path(Artifact.drafts.path) Artifact.middleman.files.reload_path(Artifact.posts.path) Artifact.middleman.files.reload_path(Artifact.uploads.path) Artifact.middleman.cache.clear # Tilt (template) cache # Artifact.middleman.sitemap.send(:reset_lookup_cache!) Artifact.middleman.sitemap.rebuild_resource_list! if Artifact.middleman.extensions[:frontmatter] # puts "Flushing frontmatter cache..." Artifact.middleman.extensions[:frontmatter].flush_cache! end end
valid_date?(str)
click to toggle source
# File lib/artifact/middleman.rb, line 205 def valid_date?(str) Time.parse(str) rescue false end