Sha256: 432d530c84c04094755e214b7ff11534d820c5aebab37ce0839bfd9e16d42cac

Contents?: true

Size: 1.3 KB

Versions: 9

Compression:

Stored size: 1.3 KB

Contents

# require 'helpers-blog'
# require 'runeblog'
require 'global'

class RuneBlog::View
  attr_reader :name, :state
  attr_accessor :publisher

  include RuneBlog::Helpers

  def initialize(name)
    raise NoBlogAccessor if RuneBlog.blog.nil?
    @blog = RuneBlog.blog
    @name = name
    @can_publish = false
    pub_file = @blog.root + "/views/#@name/publish"
    if File.exist?(pub_file) && File.size(pub_file) != 0
      @publisher = RuneBlog::Publishing.new(read_config(pub_file))
      @can_publish = true
    end
  end

  def dir
    @blog.root + "/views/#@name/"
  end

  def local_index
    dir + "/remote/index.html"
  end

  def index
    dir + "index.html"
  end

  def to_s
    @name
  end

  def publishable_files
    vdir = dir()
    remote = local_index()
    files = [remote]
    others = Dir.entries(vdir + "/remote").map {|x| "#{vdir}/remote/#{x}" }

    assets = Dir.entries("#{vdir}/assets") - %w[. ..]
    assets.map! {|x| "#{vdir}/assets/#{x}" }
    assets.reject! {|x| File.directory?(x) }
#   assets.reject! {|x| ! recent?(x) }
    files = files + others
    all = files.dup
    dirty = files.reject {|f| ! recent?(f) }
    [dirty, all, assets]
  end

  def can_publish?
    @can_publish
  end

  def recent?(file)
    File.mtime(file) > File.mtime("#{dir()}/last_published")
  rescue
    true
  end

end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
runeblog-0.2.3 lib/view.rb
runeblog-0.2.2 lib/view.rb
runeblog-0.2.1 lib/view.rb
runeblog-0.1.99 lib/view.rb
runeblog-0.1.98 lib/view.rb
runeblog-0.1.97 lib/view.rb
runeblog-0.1.96 lib/view.rb
runeblog-0.1.95 lib/view.rb
runeblog-0.1.94 lib/view.rb