Module: Sinatra::KinboteHelpers::Helpers

Defined in:
lib/sinatra/kinbote_helpers.rb

Instance Method Summary collapse

Instance Method Details

#publishObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/sinatra/kinbote_helpers.rb', line 16

def publish
  updated_files = []
  tmp_file = "/tmp/kinbote"
  
  Dir.glob("#{$site.kinbote_path}/public/**/*").each do |public_file|
    www_file = public_file.gsub("/public/", "/www/")
    next if File.directory?(public_file) || (File.exist?(www_file) && File.size(public_file) == File.size(www_file))
    FileUtils.mkdir_p(dir_from_file(www_file))
    FileUtils.cp(public_file, www_file)
    updated_files << www_file
  end
  
  FileUtils.mkdir_p("#{$site.kinbote_path}/www/css/pages")
  Dir.glob("#{$site.kinbote_path}/views/**/*.{haml,sass}").each do |file|
    next if file.include?("/.kinbote/") || file.include?("/snippets/") || file.include?("/layout.haml")
    slug = (file.include?("/views/pages/") ? slug_from_file(file) : nil)
    @page = (slug ? $site.find_page(slug) : nil)
    type = type_from_file(file)
    to_file = nil
    if @page && type == "haml"
      to_file = "#{$site.kinbote_path}/www/#{@page.slug}.html"
      File.open(tmp_file, 'w') {|f| f.write(haml(:"#{@page.path}")) }
    elsif @page && type == "sass"
      to_file = "#{$site.kinbote_path}/www/css/pages/#{@page.slug}.css"
      File.open(tmp_file, 'w') {|f| f.write(sass(:"#{@page.path.gsub(".haml", ".sass")}")) }
    elsif type == "haml"
      FileUtils.mkdir_p("#{dir_from_file(output_path(file))}")
      to_file = output_path(file)
      File.open(tmp_file, "w") {|f| f.write(render(type.to_sym, :"#{file_without_extension(view_path(file))}"))}
    elsif type == "sass"
      FileUtils.mkdir_p("#{dir_from_file(output_path(file))}")
      to_file = output_path(file)
      File.open(tmp_file, "w") {|f| f.write(render(type.to_sym, :"#{file_without_extension(view_path(file))}"))}
    end
    if to_file && (!File.exist?(to_file) || File.size(to_file) != File.size(tmp_file))
      FileUtils.mv(tmp_file, to_file)
      updated_files << to_file
    end
  end
  return updated_files.sort if !$site.config.has_key?("remote_host") || !$site.config.has_key?("remote_user") || !$site.config.has_key?("remote_pw") 
  Net::SCP.start($site.config["remote_host"], $site.config["remote_user"], :password => $site.config["remote_pw"] ) do |scp|
    scp.upload!("#{$site.kinbote_path}/www", $site.config["remote_path"], :recursive => true)
  end 
  updated_files.sort

end

#set_user_variablesObject



9
10
11
12
13
14
# File 'lib/sinatra/kinbote_helpers.rb', line 9

def set_user_variables
  @site = $site
  @pages = $site.pages
  @attributes = $site.attributes
  @attributes.each{|att| eval("@#{att.varname} = att if !@#{att.varname}")}
end

#snippet(path) ⇒ Object



5
6
7
# File 'lib/sinatra/kinbote_helpers.rb', line 5

def snippet(path)
  haml("snippets/#{path}".to_sym, :layout => false)
end