fugleman 0.1.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/LICENSE +23 -0
- data/README +24 -0
- data/fugleman.gemspec +24 -0
- data/lib/fugleman.rb +5 -0
- data/lib/nyny/helpers.rb +173 -0
- data/nyny.gemspec +24 -0
- metadata +65 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5ea2f49e7ee24e26864bdba6d17cb4be4ec53f1f
|
4
|
+
data.tar.gz: 9f9b1ed2344f6eeb32116ec8537b1a31a825094b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4a13d30e258a8de37b96b6b3c82c47e7c35d14024853fe3fdfb9b8620e59dad4d47318949052da2cb7c8a404c5238dadd797ad0414783686805223ad2e735e9e
|
7
|
+
data.tar.gz: 60b7294ad78b246b542c85f8cca684ca30ec534f1e9cfeef30ec5188ca038e1f1cb9cdd06a664477088f725fc0569e7a9829d77cf3ea72d10d848648298e0d74
|
data/LICENSE
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
|
2
|
+
Copyright (c) 2014 Kaspar Schiess
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person
|
5
|
+
obtaining a copy of this software and associated documentation
|
6
|
+
files (the "Software"), to deal in the Software without
|
7
|
+
restriction, including without limitation the rights to use,
|
8
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the
|
10
|
+
Software is furnished to do so, subject to the following
|
11
|
+
conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
18
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
20
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
21
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
22
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
23
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
|
2
|
+
# SYNOPSIS
|
3
|
+
|
4
|
+
HTML helper code. But simpler.
|
5
|
+
|
6
|
+
require 'fugleman'
|
7
|
+
|
8
|
+
# and inside your Sinatra app
|
9
|
+
|
10
|
+
helpers Fugleman::Helpers
|
11
|
+
|
12
|
+
# and then:
|
13
|
+
input_tag :text, :foo # => <input type="text" name="foo" />
|
14
|
+
...
|
15
|
+
|
16
|
+
# LICENSING
|
17
|
+
|
18
|
+
Some of the code in here started its life out as part of padrino-helpers. It
|
19
|
+
was then copied and heavily modified. This means that we take the blame for
|
20
|
+
all the bugs and the praise for none of the features.
|
21
|
+
|
22
|
+
MIT, (c) Technology Astronauts 2014
|
23
|
+
|
24
|
+
|
data/fugleman.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "fugleman"
|
5
|
+
s.version = "0.1.1"
|
6
|
+
s.summary = "Helpers and stuff for working with sinatra. Really simple."
|
7
|
+
s.homepage = "https://bitbucket.org/technologyastronauts/fugleman"
|
8
|
+
s.authors = ['Kaspar Schiess']
|
9
|
+
s.email = ["kaspar.schiess@technologyastronauts.ch"]
|
10
|
+
|
11
|
+
s.description = <<-EOF
|
12
|
+
HTML and other helper functions, for working with sinatra. Except simple.
|
13
|
+
|
14
|
+
Simplistic even. Caution, this stick has a pointed end. And it might be the
|
15
|
+
one you're holding.
|
16
|
+
EOF
|
17
|
+
|
18
|
+
s.files = Dir['**/*']
|
19
|
+
s.test_files = Dir['test/**/*'] + Dir['spec/**/*']
|
20
|
+
s.executables = Dir['bin/*'].map { |f| File.basename(f) }
|
21
|
+
s.require_paths = ["lib"]
|
22
|
+
|
23
|
+
s.add_runtime_dependency 'rack'
|
24
|
+
end
|
data/lib/fugleman.rb
ADDED
data/lib/nyny/helpers.rb
ADDED
@@ -0,0 +1,173 @@
|
|
1
|
+
|
2
|
+
# This started out life as a copy of code found in padrino, but was heavily
|
3
|
+
# simplified and then forked.
|
4
|
+
#
|
5
|
+
# NOTE This includes none of the SafeBuffer madness. Watch your escaping.
|
6
|
+
#
|
7
|
+
module Fugleman::Helpers
|
8
|
+
|
9
|
+
# ------------------------------------------------------------------ linking
|
10
|
+
|
11
|
+
# Creates a link element with given name, url and options.
|
12
|
+
#
|
13
|
+
def link_to(*args, &block)
|
14
|
+
options = args.extract_options!
|
15
|
+
name = block_given? ? '' : args.shift
|
16
|
+
|
17
|
+
|
18
|
+
url = args.first || '#'
|
19
|
+
options.reverse_merge!(:href => url)
|
20
|
+
|
21
|
+
block_given? ? content_tag(:a, options, &block) : content_tag(:a, name, options)
|
22
|
+
end
|
23
|
+
|
24
|
+
# ----------------------------------------------------------------- partials
|
25
|
+
def partial name, opts={}, &block
|
26
|
+
slim name, { layout: false }.update(opts), &block
|
27
|
+
end
|
28
|
+
|
29
|
+
# ------------------------------------------------------------ tag rendering
|
30
|
+
def input_tag(type, name=nil, options = {})
|
31
|
+
tag(
|
32
|
+
:input,
|
33
|
+
{name: name}.update(
|
34
|
+
options.reverse_merge!(:type => type)))
|
35
|
+
end
|
36
|
+
def tag(name, options = nil, open = false)
|
37
|
+
attributes = tag_attributes(options)
|
38
|
+
"<#{name}#{attributes}#{open ? '>' : ' />'}".html_safe
|
39
|
+
end
|
40
|
+
def content_tag(name, content = nil, options = nil, &block)
|
41
|
+
if block_given?
|
42
|
+
options = content if content.is_a?(Hash)
|
43
|
+
content = capture_html(&block)
|
44
|
+
end
|
45
|
+
|
46
|
+
attributes = tag_attributes(options)
|
47
|
+
output = String.new
|
48
|
+
output.concat "<#{name}#{attributes}>"
|
49
|
+
output.concat content.to_s
|
50
|
+
output.concat "</#{name}>"
|
51
|
+
|
52
|
+
output
|
53
|
+
end
|
54
|
+
|
55
|
+
# ------------------------------------------------------------------- assets
|
56
|
+
def image_tag(url, options={})
|
57
|
+
options.reverse_merge!(:src => image_path(url))
|
58
|
+
tag(:img, options)
|
59
|
+
end
|
60
|
+
def javascript_include_tag(*sources)
|
61
|
+
options = {
|
62
|
+
:type => 'text/javascript'
|
63
|
+
}.update(sources.extract_options!.symbolize_keys)
|
64
|
+
sources.flatten.inject(String.new) do |all,source|
|
65
|
+
all << content_tag(:script, nil, { :src => asset_path('javascripts/'+source+'.js') }.update(options))
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def image_path(src)
|
70
|
+
asset_path("images/" + src)
|
71
|
+
end
|
72
|
+
|
73
|
+
# Formats a path to an asset, including the assets timestamp for cache
|
74
|
+
# invalidation.
|
75
|
+
#
|
76
|
+
def asset_path(source = nil)
|
77
|
+
timestamp = asset_timestamp(source)
|
78
|
+
result_path = uri_root_path(source)
|
79
|
+
"#{result_path}#{timestamp}"
|
80
|
+
end
|
81
|
+
# Returns the timestamp mtime for an asset.
|
82
|
+
#
|
83
|
+
# asset_timestamp("some/path/to/file.png") => "?154543678"
|
84
|
+
#
|
85
|
+
def asset_timestamp(file_path)
|
86
|
+
return nil if file_path =~ /\?/ || (self.class.respond_to?(:asset_stamp) && !self.class.asset_stamp)
|
87
|
+
public_path = self.class.public_folder if self.class.respond_to?(:public_folder)
|
88
|
+
public_path ||= Padrino.root("public") if Padrino.respond_to?(:root)
|
89
|
+
public_file_path = File.join(public_path, file_path) if public_path
|
90
|
+
stamp = File.mtime(public_file_path).to_i if public_file_path && File.exist?(public_file_path)
|
91
|
+
stamp ||= Time.now.to_i
|
92
|
+
"?#{stamp}"
|
93
|
+
end
|
94
|
+
|
95
|
+
# ----------------------------------------------------------------- escapism
|
96
|
+
def escape_html(text)
|
97
|
+
Rack::Utils.escape_html(text).html_safe
|
98
|
+
end
|
99
|
+
alias h escape_html
|
100
|
+
|
101
|
+
def escape_value(string)
|
102
|
+
string.to_s.gsub(ESCAPE_REGEXP) { |c| ESCAPE_VALUES[c] }
|
103
|
+
end
|
104
|
+
|
105
|
+
# -------------------------------------------------------- delayed rendering
|
106
|
+
|
107
|
+
# For content_for, etc.. please use Sinatra::ContentFor,
|
108
|
+
# part of sinatra-contrib.
|
109
|
+
|
110
|
+
# ----------------------------------------------------------------- captures
|
111
|
+
|
112
|
+
def capture_html(*args, &block)
|
113
|
+
# block.call(*args)
|
114
|
+
end
|
115
|
+
|
116
|
+
# --------------------------------------------------------- foundation stuff
|
117
|
+
|
118
|
+
# Returns the URI root of the application with optional paths appended.
|
119
|
+
#
|
120
|
+
# uri_root_path("/some/path") => "/root/some/path"
|
121
|
+
# uri_root_path("javascripts", "test.js") => "/uri/root/javascripts/test.js"
|
122
|
+
#
|
123
|
+
def uri_root_path(*paths)
|
124
|
+
root_uri = self.class.uri_root if self.class.respond_to?(:uri_root)
|
125
|
+
File.join(ENV['RACK_BASE_URI'].to_s, root_uri || '/', *paths)
|
126
|
+
end
|
127
|
+
|
128
|
+
|
129
|
+
private
|
130
|
+
ESCAPE_VALUES = {
|
131
|
+
"&" => "&",
|
132
|
+
"<" => "<",
|
133
|
+
">" => ">",
|
134
|
+
'"' => """
|
135
|
+
}
|
136
|
+
ESCAPE_REGEXP = Regexp.union(*ESCAPE_VALUES.keys)
|
137
|
+
|
138
|
+
BOOLEAN_ATTRIBUTES = [
|
139
|
+
:autoplay,
|
140
|
+
:autofocus,
|
141
|
+
:formnovalidate,
|
142
|
+
:checked,
|
143
|
+
:disabled,
|
144
|
+
:hidden,
|
145
|
+
:loop,
|
146
|
+
:multiple,
|
147
|
+
:muted,
|
148
|
+
:readonly,
|
149
|
+
:required,
|
150
|
+
:selected,
|
151
|
+
:declare,
|
152
|
+
:defer,
|
153
|
+
:ismap,
|
154
|
+
:itemscope,
|
155
|
+
:noresize,
|
156
|
+
:novalidate
|
157
|
+
]
|
158
|
+
|
159
|
+
def tag_attributes(options)
|
160
|
+
return '' if options.nil?
|
161
|
+
attributes = options.map do |k, v|
|
162
|
+
next if v.nil? || v == false
|
163
|
+
if v.is_a?(Hash)
|
164
|
+
nested_values(k, v)
|
165
|
+
elsif BOOLEAN_ATTRIBUTES.include?(k)
|
166
|
+
%(#{k}="#{k}")
|
167
|
+
else
|
168
|
+
%(#{k}="#{escape_value(v)}")
|
169
|
+
end
|
170
|
+
end.compact
|
171
|
+
attributes.empty? ? '' : " #{attributes * ' '}"
|
172
|
+
end
|
173
|
+
end
|
data/nyny.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "nyny"
|
5
|
+
s.version = "0.1.1"
|
6
|
+
s.summary = "Helpers and stuff for working with sinatra. Really simple."
|
7
|
+
s.homepage = "https://bitbucket.org/technologyastronauts/nyny"
|
8
|
+
s.authors = ['Kaspar Schiess']
|
9
|
+
s.email = ["kaspar.schiess@technologyastronauts.ch"]
|
10
|
+
|
11
|
+
s.description = <<-EOF
|
12
|
+
HTML and other helper functions, for working with sinatra. Except simple.
|
13
|
+
|
14
|
+
Simplistic even. Caution, this stick has a pointed end. And it might be the
|
15
|
+
one you're holding.
|
16
|
+
EOF
|
17
|
+
|
18
|
+
s.files = Dir['**/*']
|
19
|
+
s.test_files = Dir['test/**/*'] + Dir['spec/**/*']
|
20
|
+
s.executables = Dir['bin/*'].map { |f| File.basename(f) }
|
21
|
+
s.require_paths = ["lib"]
|
22
|
+
|
23
|
+
s.add_runtime_dependency 'rack'
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fugleman
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kaspar Schiess
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rack
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: "HTML and other helper functions, for working with sinatra. Except simple.
|
28
|
+
\n\nSimplistic even. Caution, this stick has a pointed end. And it might be the\none
|
29
|
+
you're holding. \n"
|
30
|
+
email:
|
31
|
+
- kaspar.schiess@technologyastronauts.ch
|
32
|
+
executables: []
|
33
|
+
extensions: []
|
34
|
+
extra_rdoc_files: []
|
35
|
+
files:
|
36
|
+
- LICENSE
|
37
|
+
- README
|
38
|
+
- fugleman.gemspec
|
39
|
+
- lib/fugleman.rb
|
40
|
+
- lib/nyny/helpers.rb
|
41
|
+
- nyny.gemspec
|
42
|
+
homepage: https://bitbucket.org/technologyastronauts/fugleman
|
43
|
+
licenses: []
|
44
|
+
metadata: {}
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
requirements: []
|
60
|
+
rubyforge_project:
|
61
|
+
rubygems_version: 2.2.2
|
62
|
+
signing_key:
|
63
|
+
specification_version: 4
|
64
|
+
summary: Helpers and stuff for working with sinatra. Really simple.
|
65
|
+
test_files: []
|