nmerouze / newyork

Easy website wireframing with HAML, SASS, Red, Compass, jQuery and Polypage.

This URL has Read+Write access

newyork / main.rb
100644 103 lines (80 sloc) 2.161 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
require 'rubygems'
 
if File.exist?(dir = File.join(File.dirname(__FILE__), 'lib'))
  Gem.clear_paths
  Gem.path.unshift(File.join(dir, 'gems'))
end
 
gem 'sinatra', '~> 0.3.2'
require 'sinatra'
gem 'extlib', '~> 0.9.8'
require 'extlib'
 
module Sinatra
  
  module Sass
    def sass(content, options = {})
      require 'sass'
      require 'compass'
 
      options[:layout] = false
      options[:views_directory] = 'sass'
 
      render(:sass, content, options)
    end
    
    private
 
      def render_sass(content, options = {})
        ::Sass::Engine.new(content, {
          :style => :compact,
          :load_paths => [
            '.',
            File.dirname(__FILE__) / 'sass'
          ] + ::Compass::Frameworks::ALL.map{ |f| f.stylesheets_directory }
        }).render
      end
  end
  
  unless RUBY_PLATFORM == 'java'
    module Red
      def red(content, options = {})
        require 'red'
      
        options[:views_directory] = 'red'
      
        render(:red, content, options)
      end
    
      private
 
        def render_red(content, options = {})
          meta_class.__send__ :include, ::Red
          ::Red.__send__ :attr_accessor, :content
        
          ::Red.content = content
        
          class << ::Red
            ::Red.init
            ::Red.content.translate_to_sexp_array.red!
          end
        end
    end
  
    class EventContext
      include Red
    end
  end
  
end
 
helpers do
  def css_include_tag(*stylesheets)
    stylesheets.map do |stylesheet|
      "<link href='/stylesheets/#{stylesheet}.css' media='screen' rel='stylesheet' type='text/css' />\n"
    end
  end
  
  def js_include_tag(*javascripts)
    javascripts.map do |javascript|
      "<script type='text/javascript' src='/javascripts/#{javascript}.js'></script>\n"
    end
  end
end
 
get '/' do
  haml :index
end
 
get '/:name' do
  haml params[:name].to_sym
end
 
get '/stylesheets/:name.css' do
  content_type 'text/css', :charset => 'utf-8'
  sass params[:name].to_sym
end
 
unless RUBY_PLATFORM == 'java'
  get '/javascripts/:name.js' do
    content_type 'text/javascript', :charset => 'utf-8'
    red params[:name].to_sym
  end
end