Module: Sinatra::KinboteHelpers::Helpers

Defined in:
lib/sinatra/kinbote_helpers.rb

Instance Method Summary collapse

Instance Method Details

#kv_to_attributes(keys, values) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/sinatra/kinbote_helpers.rb', line 16

def kv_to_attributes(keys, values)
  attributes = {}
  keys.each_with_index do |key, i|
    next if key.size == 0
    attributes[key] = [] if !attributes.has_key?(key)
    attributes[key] << values[i] if !attributes[key].include?(values[i])
  end
  attributes
end

#publishObject



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
# File 'lib/sinatra/kinbote_helpers.rb', line 26

def publish
  FileUtils.rm_rf("#{$site.kinbote_path}/www")
  FileUtils.mkdir_p("#{$site.kinbote_path}/www/css/pages")
  FileUtils.copy_entry("#{$site.kinbote_path}/public", "#{$site.kinbote_path}/www")
  files = Dir.glob("#{$site.kinbote_path}/views/**/*.{haml,sass}")
  files.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)
    if @page && type == "haml"
      File.open("#{$site.kinbote_path}/www/#{@page.slug}.html", 'w') {|f| f.write(haml(:"#{@page.path}")) }
    elsif @page && type == "sass"
      File.open("#{$site.kinbote_path}/www/css/pages/#{@page.slug}.css", 'w') {|f| f.write(sass(:"#{@page.path.gsub(".haml", ".sass")}")) }
    elsif type == "haml"
      FileUtils.mkdir_p("#{dir_from_file(output_path(file))}")
      File.open(output_path(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))}")
      File.open(output_path(file), "w") {|f| f.write(render(type.to_sym, :"#{file_without_extension(view_path(file))}"))}
    end
  end
  return 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 
end

#set_user_globalsObject



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

def set_user_globals
  @site = $site
  @pages = $site.pages
  @attributes = $site.attributes
  @attributes.each{|att| eval("@#{att._varname} = att")}
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