Skip to content
This repository has been archived by the owner on Apr 9, 2019. It is now read-only.

Commit

Permalink
move the demo design into the sinatra app; upgrade to the latest sina…
Browse files Browse the repository at this point in the history
…tra so we can use compass
  • Loading branch information
timriley committed Jan 22, 2009
1 parent 53a3081 commit 00afdd1
Show file tree
Hide file tree
Showing 10 changed files with 196 additions and 312 deletions.
6 changes: 5 additions & 1 deletion Readme.textile
Original file line number Original file line Diff line number Diff line change
@@ -1,3 +1,7 @@
h1. unfuddle-mirror h1. unfuddle-mirror


A Sinatra application that provides access to Unfuddle tickets without requiring a user account. Ideal for user access to helpdesk tickets. A Sinatra application that provides access to Unfuddle tickets without requiring a user account. Ideal for user access to helpdesk tickets.

h1. Acknowledgements

* Tim Lucas, for the helpers & other various tricks from "toolmantim.com":http://github.com/toolmantim/toolmantim/tree/master/toolmantim.rb
Binary file removed design/src/grid.png
Binary file not shown.
20 changes: 15 additions & 5 deletions lib/unfuddle.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,8 +1,18 @@
# This method is needed for HTTParty to work properly
# Extracted from http://github.com/wycats/merb-extlib/tree/master/lib/merb-extlib/string.rb
class String
def snake_case
return self.downcase if self =~ /^[A-Z]+$/
self.gsub(/([A-Z]+)(?=[A-Z][a-z]?)|\B[A-Z]/, '_\&') =~ /_*(.*)/
return $+.downcase
end
end

class Unfuddle class Unfuddle
include HTTParty include HTTParty


base_uri "https://#{Sinatra.options.unfuddle_subdomain}.unfuddle.com/api/v1/projects/#{Sinatra.options.unfuddle_project_id}" base_uri "https://#{Sinatra::Application.unfuddle_subdomain}.unfuddle.com/api/v1/projects/#{Sinatra::Application.unfuddle_project_id}"
basic_auth Sinatra.options.unfuddle_username, Sinatra.options.unfuddle_password basic_auth Sinatra::Application.unfuddle_username, Sinatra::Application.unfuddle_password


format :xml format :xml


Expand All @@ -16,12 +26,12 @@ def self.get_ticket(id)


# HTTParty doesn't like that this request returns a nil body. Let's do it manually for now. # HTTParty doesn't like that this request returns a nil body. Let's do it manually for now.
def self.post_ticket(params) def self.post_ticket(params)
http = Net::HTTP.new("#{Sinatra.options.unfuddle_subdomain}.unfuddle.com", 443) http = Net::HTTP.new("#{Sinatra::Application.unfuddle_subdomain}.unfuddle.com", 443)
http.use_ssl = true http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE http.verify_mode = OpenSSL::SSL::VERIFY_NONE


request = Net::HTTP::Post.new("/api/v1/projects/#{Sinatra.options.unfuddle_project_id}/tickets", {'Content-type' => 'application/xml'}) request = Net::HTTP::Post.new("/api/v1/projects/#{Sinatra::Application.unfuddle_project_id}/tickets", {'Content-type' => 'application/xml'})
request.basic_auth Sinatra.options.unfuddle_username, Sinatra.options.unfuddle_password request.basic_auth Sinatra::Application.unfuddle_username, Sinatra::Application.unfuddle_password
request.body = "<ticket><priority>3</priority><summary>#{params[:name]} || #{params[:summary]}</summary><description>#{params[:description]}</description></ticket>" request.body = "<ticket><priority>3</priority><summary>#{params[:name]} || #{params[:summary]}</summary><description>#{params[:description]}</description></ticket>"


response = http.request(request) response = http.request(request)
Expand Down
50 changes: 26 additions & 24 deletions unfuddle_mirror.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,62 +1,64 @@
require 'rubygems' require 'rubygems'

gem 'sinatra-sinatra', '~> 0.9'
require 'sinatra'

require 'yaml' require 'yaml'
require 'haml' require 'haml'
require 'sinatra'
require 'httparty' require 'httparty'
require 'net/http' require 'net/http'
require 'compass'


configure do configure do
require File.join(File.dirname(__FILE__), '/app_config') require File.join(File.dirname(__FILE__), 'app_config')
enable :sessions enable :sessions
end end


require File.join(File.dirname(__FILE__), '/lib/unfuddle') require File.join(File.dirname(__FILE__), 'lib', 'unfuddle')

# This method is needed for HTTParty to work properly
# Extracted from http://github.com/wycats/merb-extlib/tree/master/lib/merb-extlib/string.rb
class String
def snake_case
return self.downcase if self =~ /^[A-Z]+$/
self.gsub(/([A-Z]+)(?=[A-Z][a-z]?)|\B[A-Z]/, '_\&') =~ /_*(.*)/
return $+.downcase
end
end


helpers do helpers do
# Thanks to http://www.gittr.com/index.php/archive/using-rackutils-in-sinatra-escape_html-h-in-rails/
include Rack::Utils include Rack::Utils
alias_method :h, :escape_html alias_method :h, :escape_html


# Thanks to Tim Lucas for these helpers, taken from http://github.com/toolmantim/toolmantim/tree/master/toolmantim.rb
def versioned_stylesheet(stylesheet) def versioned_stylesheet(stylesheet)
"/stylesheets/#{stylesheet}.css?" + File.mtime(File.join(Sinatra.application.options.views, "stylesheets", "#{stylesheet}.sass")).to_i.to_s # "/stylesheets/#{stylesheet}.css?" + File.mtime(File.join(Sinatra::Application.views, "stylesheets", "#{stylesheet}.sass")).to_i.to_s
"/stylesheets/#{stylesheet}.css"
end end
def versioned_js(js) def versioned_js(js)
"/javascripts/#{js}.js?" + File.mtime(File.join(Sinatra.application.options.public, "javascripts", "#{js}.js")).to_i.to_s "/javascripts/#{js}.js?" + File.mtime(File.join(Sinatra::Application.public, "javascripts", "#{js}.js")).to_i.to_s
end end
def partial(name) def partial(name)
haml(:"_#{name}", :layout => false) haml(:"_#{name}", :layout => false)
end end

def cycle
@_cycle ||= reset_cycle
@_cycle = [@_cycle.pop] + @_cycle
@_cycle.first
end
def reset_cycle
@_cycle = %w(odd even)
end
end end


get '/' do get '/' do
@ticket_report = Unfuddle.get_ticket_report(Sinatra.options.unfuddle_ticket_report_id) @ticket_report = Unfuddle.get_ticket_report(Sinatra::Application.unfuddle_ticket_report_id)
haml :ticket_report haml :ticket_report
end end


get "/stylesheets/screen.css" do %w( screen ie print ).each do |stylesheet|
content_type 'text/css' get "/stylesheets/#{stylesheet}.css" do
headers "Expires" => (Time.now + 60*60*24*356*3).httpdate # Cache for 3 years content_type 'text/css'
sass :"stylesheets/screen" headers 'Expires' => (Time.now + 60*60*24*356*3).httpdate # Cache for 3 years
sass :"stylesheets/#{stylesheet}", { :sass => { :load_paths => ([ File.join(File.dirname(__FILE__), 'views', 'stylesheets') ] + Compass::Frameworks::ALL.map { |f| f.stylesheets_directory }) } }
end
end end


get '/tickets/new' do get '/tickets/new' do
haml :new_ticket haml :new_ticket
end end


post '/tickets' do post '/tickets' do
p params

success = Unfuddle.post_ticket(params) success = Unfuddle.post_ticket(params)


set_cookie('notice', success ? 'ticket_successful' : 'ticket_failed') set_cookie('notice', success ? 'ticket_successful' : 'ticket_failed')
Expand Down
41 changes: 30 additions & 11 deletions views/layout.haml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,14 +4,33 @@
%head %head
%meta{'http-equiv' => 'Content-Type', :content => 'text/html; charset=utf-8'}/ %meta{'http-equiv' => 'Content-Type', :content => 'text/html; charset=utf-8'}/
%title= "Helpdesk Tickets - #{@title}" %title= "Helpdesk Tickets - #{@title}"
%link{:href => versioned_stylesheet('screen'), :media => "screen", :rel => "stylesheet", :type => "text/css"}/ %link{:href => versioned_stylesheet('screen'), :media => 'screen', :rel => 'stylesheet', :type => 'text/css'}/

%link{:href => versioned_stylesheet('print'), :media => 'print', :rel => 'stylesheet', :type => 'text/css'}/
%body /[if IE]
#header %link{:href => versioned_stylesheet('ie'), :media => 'screen', :rel => 'stylesheet', :type => 'text/css'}/
%h1
%a{:href => '/'} Helpdesk Tickets %body#index.blueprint

#menubar
#wrapper .container
#content %ul#app-suite-links
%h1= @title %li.first
= yield %strong
%a{:href => '#'} AMC
%li
%a{:href => '#'} News
%li
%a{:href => '#'} Phones
%li
%a{:href => '#'} Helpdesk
%ul#site-actions
%li
%a{:href => '#'} Help

#titlebar
.container
#header
%h1
%a{:href => '/'} IT Helpdesk

.container
= yield
50 changes: 50 additions & 0 deletions views/stylesheets/_base.sass
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,50 @@
@import compass/reset.sass
@import compass/utilities.sass
@import blueprint.sass
@import blueprint/modules/debug.sass

=reset-blueprint-typography
body
:font-size 85%
th
:background inherit
tr.even td
:background inherit

=has-menubar
#menubar
:width 100%
:background-color #2b2b2b
:border-bottom 1px solid #eee
:color #fff
a
:color #fff
:text-decoration none
#app-suite-links
:float left
+horizontal-list
#site-actions
:float right
+horizontal-list

=has-titlebar
#titlebar
:width 100%
:min-height 3em
:margin-bottom 1.5em
:background #279914 url(/images/body-bg.png) repeat-x
#header
+column(24)
:padding-top 1em
h1
:font-size 2em
:font-weight bold
:margin-bottom 0.75em
:color #fff
+column(24)
a
:text-decoration none
:color #fff

h1
+header-text
3 changes: 3 additions & 0 deletions views/stylesheets/ie.sass
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,3 @@
@import blueprint.sass

+blueprint-ie
3 changes: 3 additions & 0 deletions views/stylesheets/print.sass
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,3 @@
@import blueprint.sass

+blueprint-print
Loading

0 comments on commit 00afdd1

Please sign in to comment.