Sha256: 414254c77d3d066eb318949d436ce8cb748ae7a5adfc689e9dd86e29c233404d

Contents?: true

Size: 1.4 KB

Versions: 22

Compression:

Stored size: 1.4 KB

Contents

# encoding: utf-8
require 'sinatra/base'
require 'erb'

module WebTranslateIt
  class Server < Sinatra::Base
    attr_reader :config
    
    dir = File.dirname(File.expand_path(__FILE__))

    set :views,  "#{dir}/views"
    set :public, "#{dir}/public"
    set :static, true
    set :lock, true
        
    helpers do
      def wti_root
        ""
      end
      
      def highlight(value, expected)
        return if value.nil?
        print_value = value == true ? "Yes" : "No"
        value == expected ? "<em>#{print_value}</em>" : "<em class=\"information\">#{print_value}</em>"
      end
    end
    
    get '/' do
      @config = WebTranslateIt::Configuration.new('.')
      erb :index, :locals => { :config => config, :locale => "" }
    end
    
    get '/:locale' do
      @config = WebTranslateIt::Configuration.new('.')
      erb :index, :locals => { :config => config, :locale => params[:locale] }
    end
    
    post '/pull/' do
      `wti pull`
      redirect "/"
    end
    
    post '/pull/:locale' do
      `wti pull -l #{params[:locale]}`
      redirect "/#{params[:locale]}"
    end
    
    def self.start(host, port)
      puts "Starting wti server..."
      Dir::mkdir('log') unless FileTest::directory?('log')
      logger = ::File.open("log/webtranslateit.log", "a+")
      STDOUT.reopen(logger)
      STDERR.reopen(logger)
      WebTranslateIt::Server.run! :host => host, :port => port
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
web_translate_it-1.8.4 lib/web_translate_it/server.rb
web_translate_it-1.8.3 lib/web_translate_it/server.rb
web_translate_it-1.8.2.3 lib/web_translate_it/server.rb
web_translate_it-1.8.2.2 lib/web_translate_it/server.rb
web_translate_it-1.8.2.1 lib/web_translate_it/server.rb
web_translate_it-1.8.2.0 lib/web_translate_it/server.rb
web_translate_it-1.8.1.9 lib/web_translate_it/server.rb
web_translate_it-1.8.1.8 lib/web_translate_it/server.rb
web_translate_it-1.8.1.7 lib/web_translate_it/server.rb
web_translate_it-1.8.1.6 lib/web_translate_it/server.rb
web_translate_it-1.8.1.5 lib/web_translate_it/server.rb
web_translate_it-1.8.1.4 lib/web_translate_it/server.rb
web_translate_it-1.8.1.3 lib/web_translate_it/server.rb
web_translate_it-1.8.1.2 lib/web_translate_it/server.rb
web_translate_it-1.8.1.1 lib/web_translate_it/server.rb
web_translate_it-1.8.1.0 lib/web_translate_it/server.rb
web_translate_it-1.8.0.1 lib/web_translate_it/server.rb
web_translate_it-1.8.0.0 lib/web_translate_it/server.rb
web_translate_it-1.7.3.1 lib/web_translate_it/server.rb
web_translate_it-1.7.3.0 lib/web_translate_it/server.rb