module Util

Constants

Config
Token

Public Instance Methods

add_to_git() click to toggle source
# File lib/util.rb, line 81
def add_to_git
  g = Git.open content_root
  g.add(:all=>true)
  g.commit('autocommit')
  g.push(g.remote('origin'),'master',force: true) if has_remote?(g)

rescue Git::GitExecuteError => error
  puts error.message.split(":")[1]
end
alter_index_html() { |doc| ... } click to toggle source
# File lib/util.rb, line 53
def alter_index_html
  index = "#{content_root}/client/index.html"
  doc = nil
  File.open index,"r+" do |file|
    doc = Nokogiri::HTML(file)
    yield doc
  end
  File.open(index,'w+') { |file| file.write(doc.to_html)} if doc
end
content_root() click to toggle source
# File lib/util.rb, line 10
def content_root
  return @root_dir if @root_dir
  search_dir = Dir.pwd
  while search_dir && !File.exist?("#{search_dir}/config.yml")
    parent = File.dirname(search_dir)
    # project_root wird entweder der Root-pfad oder false. Wenn es false
    # wird, bricht die Schleife ab. Vgl. Rails
    search_dir = (parent != search_dir) && parent
  end
  project_root = search_dir if File.exist? "#{search_dir}/config.yml"
  raise 'you are not within a presentation-project.' unless project_root
  @root_dir = Pathname.new(File.realpath project_root)
end
each_presentation(&block) click to toggle source
# File lib/util.rb, line 38
def each_presentation(&block)
  path = "#{content_root}/master/slides"
  Dir.entries(path)
      .select { |entry| !entry.start_with? '.'}
      .each{ | entry | presentation(entry,&block) }
end
git_repository?() click to toggle source

git stuff

# File lib/util.rb, line 72
def git_repository?
  File.exist? "#{content_root}/.git"
end
has_remote?(git) click to toggle source
# File lib/util.rb, line 91
def has_remote?(git)
  git.remotes.count > 0
end
init_git(project_path,remote=nil) click to toggle source
# File lib/util.rb, line 76
def init_git(project_path,remote=nil)
  g = Git.init project_path
  g.add_remote 'origin',remote if remote
end
parse_config() click to toggle source
# File lib/util.rb, line 25
def parse_config
  config = YAML.load_file("#{content_root}/config.yml")
  Config.new(config['host'],config['port'],config['project_name'])
end
presentation(name,&block) click to toggle source
# File lib/util.rb, line 46
def presentation(name,&block)
  master_path = "#{content_root}/master/slides/#{name}"
  client_path = "#{content_root}/client/slides/#{name}"
  block.call master_path,client_path
end
pull_from_git(path) click to toggle source
# File lib/util.rb, line 95
def pull_from_git(path)
  g = Git.open(path)
  g.pull('origin','master')
end
request_token() click to toggle source
# File lib/util.rb, line 30
def request_token
  host = parse_config.host
  puts "request token from: http://#{host}"
  hash = JSON.parse(Net::HTTP.get(host, '/token'))
  Token.new(hash['socketId'],hash['secret'])
end