sinatra-triforce 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/sinatra-triforce.rb +164 -0
- metadata +43 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1eee5dd578ab67fdaf2ec942c90240a1dffefcba
|
4
|
+
data.tar.gz: 19a1df4e3c8bd1f0f228ecd7ff775658636de212
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8ea8404e9bd6e0681c94ab6e862acbe213899fcf144f319dd4ae539003264d1f715a719e32393d305f710e0037a5c440d6c25569c547a07a71602ddfa281dcec
|
7
|
+
data.tar.gz: 5fc35e226ea547b9c83174cbde99d1ce8b6fc7b12c391f2ca577e633a1bc5e4f5a47887093158865dd478bde6f20b9fb661300a17a76f89e4e11841f9ec72cc3
|
@@ -0,0 +1,164 @@
|
|
1
|
+
require 'haml'
|
2
|
+
require 'sass'
|
3
|
+
require 'coffee-script'
|
4
|
+
require 'sinatra/base'
|
5
|
+
module Sinatra
|
6
|
+
module Hipster
|
7
|
+
@@assets = {:css => ['/styles/' , 'styles'],
|
8
|
+
:js => ['/scripts/', 'scripts'],
|
9
|
+
:png => ['/images/' , 'images'],
|
10
|
+
:jpg => ['/images/' , 'images'],
|
11
|
+
:gif => ['/images/' , 'images'],
|
12
|
+
:eot => ['/fonts/' , 'fonts'],
|
13
|
+
:woff => ['/fonts/' , 'fonts'],
|
14
|
+
:ttf => ['/fonts/' , 'fonts'],
|
15
|
+
:svg => ['/fonts/' , 'fonts'],
|
16
|
+
:otf => ['/fonts/' , 'fonts'],
|
17
|
+
:scss => [nil , 'styles'],
|
18
|
+
:sass => [nil , 'styles'],
|
19
|
+
:coffee => [nil , 'scripts']}
|
20
|
+
|
21
|
+
def self.ensure_slash(str)
|
22
|
+
return "#{str}/" unless str[-1] == '/'
|
23
|
+
str
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.uri_for(ext, uri)
|
27
|
+
raise "#{ext} is unknown, use the set_for method first." unless @assets[ext]
|
28
|
+
@@assets[ext][0] = uri
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.path_for(ext, path)
|
32
|
+
raise "#{ext} is unknown, use the set_for method first." unless @@assets[ext]
|
33
|
+
@@assets[ext][1] = self::ensure_slash path
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.set_for(*args)
|
37
|
+
uri = args[1].class == Hash ? args[1][:uri] : args[1]
|
38
|
+
path = args[1].class == Hash ? args[1][:path] : args[2]
|
39
|
+
@@assets[args[0]] = [uri, path]
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.get_assets; @@assets; end
|
43
|
+
|
44
|
+
def self.resource_link(r, type, ie = nil)
|
45
|
+
resource = r.class == String ? r : "#{@@assets[type][0]}#{r}.#{type}"
|
46
|
+
tag = case type
|
47
|
+
when :js then "<script src='#{resource}'></script>"
|
48
|
+
when :css then "<link rel='stylesheet' href='#{resource}'/>"
|
49
|
+
end
|
50
|
+
return "#{tag}\n" unless ie
|
51
|
+
<<-END.gsub(/^ {6}/, '')
|
52
|
+
<!--[if #{ie.upcase}]>
|
53
|
+
#{tag}
|
54
|
+
<![endif]-->
|
55
|
+
END
|
56
|
+
end
|
57
|
+
|
58
|
+
module Helpers
|
59
|
+
@@id = lambda do |id, css_class=nil|
|
60
|
+
" id='#{id}' name='#{id}'#{" class='#{css_class}'" if css_class} "
|
61
|
+
end
|
62
|
+
def js(src, ie = nil); Hipster::resource_link src, :js, ie; end
|
63
|
+
def css(href, ie = nil); Hipster::resource_link href, :css, ie; end
|
64
|
+
def txt_box(id, css_c = nil)
|
65
|
+
"<input#{@@id.call id, css_c}type='text'></input>\n"
|
66
|
+
end
|
67
|
+
def label(id, txt, label_for = nil)
|
68
|
+
"<label#{@@id.call "#{id}_label"}for='#{label_for ? label_for : id}'>#{txt}</label>\n"
|
69
|
+
end
|
70
|
+
def submit_form(id, txt, css_c = nil)
|
71
|
+
"<input#{@@id.call id, css_c}type='submit' value='#{txt}'></input>\n"
|
72
|
+
end
|
73
|
+
def pw_box(id, css_c = nil)
|
74
|
+
"<input#{@@id.call id, css_c}type='password'></input>\n"
|
75
|
+
end
|
76
|
+
def select_box(id, css_c = nil)
|
77
|
+
"<select#{@@id.call id, css_c}></select>\n"
|
78
|
+
end
|
79
|
+
def label_txt(id, label_txt); "#{label id, label_txt}#{txt_box id}"; end
|
80
|
+
def label_pw (id, label_txt); "#{label id, label_txt}#{pw_box id}"; end
|
81
|
+
def label_select(id, label_text)
|
82
|
+
"#{label id, label_text}#{select_box id}"
|
83
|
+
end
|
84
|
+
def asset_list(assets)
|
85
|
+
txt = ''
|
86
|
+
assets.each do |asset|
|
87
|
+
txt = "#{txt}#{send(*asset)}" if [:js,:css].include? asset[0]
|
88
|
+
end
|
89
|
+
txt
|
90
|
+
end
|
91
|
+
def font(name)
|
92
|
+
assets = Hipster::get_assets
|
93
|
+
file = name.downcase
|
94
|
+
<<-END.gsub(/^ {8}/, '')
|
95
|
+
<style>
|
96
|
+
@font-face {
|
97
|
+
font-family: '#{name}';
|
98
|
+
src: url('#{assets[:eot][0]}#{file}.eot?#iefix') format('embedded-opentype'),
|
99
|
+
url('#{assets[:woff][0]}#{file}.woff') format('woff'),
|
100
|
+
url('#{assets[:ttf][0]}#{file}.ttf') format('truetype'),
|
101
|
+
url('#{assets[:svg][0]}#{file}.svg#svgFontName') format('svg');
|
102
|
+
font-weight: normal
|
103
|
+
font-style: normal
|
104
|
+
}
|
105
|
+
</style>
|
106
|
+
END
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def self.get_file(file, type, uri = nil)
|
111
|
+
return nil unless ensure_slash(uri) == @@assets[type.to_sym][0]
|
112
|
+
glob = lambda { |t = nil| Dir.glob("#{@@assets[type.to_sym][1]}**/#{file}.#{t || type}")[0] }
|
113
|
+
case type.to_sym
|
114
|
+
when :js
|
115
|
+
if f = glob.call then return [file, :js] end
|
116
|
+
if glob.call(:coffee) then return [file, :coffee] end
|
117
|
+
when :css
|
118
|
+
if f = glob.call then return [file, :css] end
|
119
|
+
if glob.call(:sass) then return [file, :sass] end
|
120
|
+
else
|
121
|
+
if f = glob.call(type.to_sym) then return [file,type.to_sym] end
|
122
|
+
end
|
123
|
+
nil
|
124
|
+
end
|
125
|
+
|
126
|
+
class << self
|
127
|
+
def file_types
|
128
|
+
@@assets.keys.join '|'
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
def self.get_content_type(file)
|
133
|
+
return 'text/javascript' if file.split('.').last == 'js'
|
134
|
+
return 'text/css' if file.split('.').last == 'css'
|
135
|
+
return 'application/font-woff' if file.split('.').last == 'woff'
|
136
|
+
return 'application/vnd.ms-fontobject' if file.split('.').last == 'eot'
|
137
|
+
return 'application/x-font-ttf' if file.split('.').last == 'ttf'
|
138
|
+
return 'application/x-font-opentype' if file.split('.').last == 'otf'
|
139
|
+
return 'application/svg+xml' if file.split('.').last == 'svg'
|
140
|
+
IO.popen(['file', '--brief', '--mime-type', file]).read.chomp
|
141
|
+
end
|
142
|
+
|
143
|
+
def self.registered(app)
|
144
|
+
app.helpers Hipster::Helpers
|
145
|
+
app.get %r!(.+)?/(.+)\.(#{file_types})$! do
|
146
|
+
#last_modified DateTime.new 2010, 10, 10
|
147
|
+
#cache_control :public, :max_age => 15
|
148
|
+
file = Hipster::get_file params[:captures][1], params[:captures][2], params[:captures][0] || ''
|
149
|
+
halt 404 unless file
|
150
|
+
path = lambda { Hipster::ensure_slash @@assets[file[1]][1] }
|
151
|
+
last_modified File.open("#{path.call}#{file[0]}.#{file[1]}").mtime
|
152
|
+
return coffee file[0].to_sym, :views => path.call if file[1] == :coffee
|
153
|
+
return sass file[0].to_sym, :views => path.call if file[1] == :sass
|
154
|
+
target = "#{path.call}#{file[0]}.#{file[1]}"
|
155
|
+
content_type Hipster::get_content_type(target)
|
156
|
+
resource = File.open target
|
157
|
+
last_modified resource.mtime
|
158
|
+
return resource.read
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
register Hipster
|
164
|
+
end
|
metadata
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sinatra-triforce
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Leo Stanley
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-06-05 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: '0 Configuration HAML + SASS + CoffeeScript, '
|
14
|
+
email: leo@byteio.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/sinatra-triforce.rb
|
20
|
+
homepage:
|
21
|
+
licenses: []
|
22
|
+
metadata: {}
|
23
|
+
post_install_message:
|
24
|
+
rdoc_options: []
|
25
|
+
require_paths:
|
26
|
+
- lib
|
27
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
29
|
+
- - '>='
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: '0'
|
32
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - '>='
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
requirements: []
|
38
|
+
rubyforge_project:
|
39
|
+
rubygems_version: 2.0.3
|
40
|
+
signing_key:
|
41
|
+
specification_version: 4
|
42
|
+
summary: Instantly embrace the power of HAML, SASS & CoffeeScript.
|
43
|
+
test_files: []
|