args-handler 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +52 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/lib/args-handler.rb +362 -0
- data/spec/args-handler_spec.rb +35 -0
- data/spec/spec_helper.rb +12 -0
- metadata +157 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
gem "knjrbfw"
|
7
|
+
gem "php4r"
|
8
|
+
|
9
|
+
# Add dependencies to develop your gem here.
|
10
|
+
# Include everything needed to run rake, tests, features, etc.
|
11
|
+
group :development do
|
12
|
+
gem "rspec", "~> 2.8.0"
|
13
|
+
gem "rdoc", "~> 3.12"
|
14
|
+
gem "bundler", ">= 1.0.0"
|
15
|
+
gem "jeweler", "~> 1.8.4"
|
16
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
datet (0.0.25)
|
5
|
+
diff-lcs (1.1.3)
|
6
|
+
git (1.2.5)
|
7
|
+
http2 (0.0.13)
|
8
|
+
jeweler (1.8.4)
|
9
|
+
bundler (~> 1.0)
|
10
|
+
git (>= 1.2.5)
|
11
|
+
rake
|
12
|
+
rdoc
|
13
|
+
json (1.7.7)
|
14
|
+
knjrbfw (0.0.104)
|
15
|
+
datet
|
16
|
+
http2
|
17
|
+
php4r
|
18
|
+
ruby_process
|
19
|
+
tsafe
|
20
|
+
wref
|
21
|
+
php4r (0.0.4)
|
22
|
+
datet
|
23
|
+
http2
|
24
|
+
string-strtr
|
25
|
+
rake (10.0.4)
|
26
|
+
rdoc (3.12.2)
|
27
|
+
json (~> 1.4)
|
28
|
+
rspec (2.8.0)
|
29
|
+
rspec-core (~> 2.8.0)
|
30
|
+
rspec-expectations (~> 2.8.0)
|
31
|
+
rspec-mocks (~> 2.8.0)
|
32
|
+
rspec-core (2.8.0)
|
33
|
+
rspec-expectations (2.8.0)
|
34
|
+
diff-lcs (~> 1.1.2)
|
35
|
+
rspec-mocks (2.8.0)
|
36
|
+
ruby_process (0.0.8)
|
37
|
+
tsafe
|
38
|
+
wref
|
39
|
+
string-strtr (0.0.3)
|
40
|
+
tsafe (0.0.11)
|
41
|
+
wref (0.0.6)
|
42
|
+
|
43
|
+
PLATFORMS
|
44
|
+
ruby
|
45
|
+
|
46
|
+
DEPENDENCIES
|
47
|
+
bundler (>= 1.0.0)
|
48
|
+
jeweler (~> 1.8.4)
|
49
|
+
knjrbfw
|
50
|
+
php4r
|
51
|
+
rdoc (~> 3.12)
|
52
|
+
rspec (~> 2.8.0)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2013 kaspernj
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= args-handler
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to args-handler
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
9
|
+
* Fork the project.
|
10
|
+
* Start a feature/bugfix branch.
|
11
|
+
* Commit and push until you are happy with your contribution.
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2013 kaspernj. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "args-handler"
|
18
|
+
gem.homepage = "http://github.com/kaspernj/args-handler"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{A small library to generate HTML for wished arguments form hashes.}
|
21
|
+
gem.description = %Q{A small library to generate HTML for wished arguments form hashes.}
|
22
|
+
gem.email = "k@spernj.org"
|
23
|
+
gem.authors = ["kaspernj"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
task :default => :spec
|
40
|
+
|
41
|
+
require 'rdoc/task'
|
42
|
+
Rake::RDocTask.new do |rdoc|
|
43
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
44
|
+
|
45
|
+
rdoc.rdoc_dir = 'rdoc'
|
46
|
+
rdoc.title = "args-handler #{version}"
|
47
|
+
rdoc.rdoc_files.include('README*')
|
48
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
49
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
data/lib/args-handler.rb
ADDED
@@ -0,0 +1,362 @@
|
|
1
|
+
require "knjrbfw"
|
2
|
+
require "php4r"
|
3
|
+
|
4
|
+
class ArgsHandler
|
5
|
+
def self.checkval(value, val1, val2 = nil)
|
6
|
+
if val2 != nil
|
7
|
+
if !value or value == "" or value == "false"
|
8
|
+
return val2
|
9
|
+
else
|
10
|
+
return val1
|
11
|
+
end
|
12
|
+
else
|
13
|
+
if !value or value == "" or value == "false"
|
14
|
+
return val1
|
15
|
+
else
|
16
|
+
return value
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.inputs(arr)
|
22
|
+
html = ""
|
23
|
+
arr.each do |args|
|
24
|
+
if RUBY_ENGINE == "rbx"
|
25
|
+
html << self.input(args).to_s.encode(html.encoding)
|
26
|
+
else
|
27
|
+
html << self.input(args)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
return html
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.style_html(css)
|
35
|
+
return "" if css.length <= 0
|
36
|
+
|
37
|
+
str = " style=\""
|
38
|
+
|
39
|
+
css.each do |key, val|
|
40
|
+
str << "#{key}: #{val};"
|
41
|
+
end
|
42
|
+
|
43
|
+
str << "\""
|
44
|
+
|
45
|
+
return str
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.attr_html(attrs)
|
49
|
+
return "" if attrs.length <= 0
|
50
|
+
|
51
|
+
html = ""
|
52
|
+
attrs.each do |key, val|
|
53
|
+
html << " #{key}=\"#{html_escape(val)}\""
|
54
|
+
end
|
55
|
+
|
56
|
+
return html
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.input(args)
|
60
|
+
if args.key?(:value)
|
61
|
+
if args[:value].is_a?(Array) and (args[:value].first.is_a?(NilClass) or args[:value].first == false)
|
62
|
+
value = nil
|
63
|
+
elsif args[:value].is_a?(Array)
|
64
|
+
if !args[:value][2] or args[:value][2] == :key
|
65
|
+
value = args[:value].first[args[:value][1]]
|
66
|
+
elsif args[:value][2] == :callb
|
67
|
+
value = args[:value].first.send(args[:value][1])
|
68
|
+
else
|
69
|
+
value = args[:value]
|
70
|
+
end
|
71
|
+
elsif args[:value].is_a?(String) or args[:value].is_a?(Integer)
|
72
|
+
value = args[:value].to_s
|
73
|
+
else
|
74
|
+
value = args[:value]
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
args[:value_default] = args[:default] if args[:default]
|
79
|
+
|
80
|
+
if value.is_a?(NilClass) and args[:value_default]
|
81
|
+
value = args[:value_default]
|
82
|
+
elsif value.is_a?(NilClass)
|
83
|
+
value = ""
|
84
|
+
end
|
85
|
+
|
86
|
+
if value and args.key?(:value_func) and args[:value_func]
|
87
|
+
cback = args[:value_func]
|
88
|
+
|
89
|
+
if cback.is_a?(Method)
|
90
|
+
value = cback.call(value)
|
91
|
+
elsif cback.is_a?(Array)
|
92
|
+
value = Php4r.call_user_func(args[:value_func], value)
|
93
|
+
elsif cback.is_a?(Proc)
|
94
|
+
value = cback.call(value)
|
95
|
+
else
|
96
|
+
raise "Unknown class: #{cback.class.name}."
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
value = args[:values] if args[:values]
|
101
|
+
args[:id] = args[:name] if !args[:id]
|
102
|
+
|
103
|
+
if !args[:type]
|
104
|
+
if args[:opts]
|
105
|
+
args[:type] = :select
|
106
|
+
elsif args[:name] and args[:name].to_s[0..2] == "che"
|
107
|
+
args[:type] = :checkbox
|
108
|
+
elsif args[:name] and args[:name].to_s[0..3] == "file"
|
109
|
+
args[:type] = :file
|
110
|
+
else
|
111
|
+
args[:type] = :text
|
112
|
+
end
|
113
|
+
else
|
114
|
+
args[:type] = args[:type].to_sym
|
115
|
+
end
|
116
|
+
|
117
|
+
attr = {
|
118
|
+
"name" => args[:name],
|
119
|
+
"id" => args[:id],
|
120
|
+
"type" => args[:type],
|
121
|
+
"class" => "input_#{args[:type]}"
|
122
|
+
}
|
123
|
+
attr.merge!(args[:attr]) if args[:attr]
|
124
|
+
attr["disabled"] = "disabled" if args[:disabled]
|
125
|
+
attr["maxlength"] = args[:maxlength] if args.key?(:maxlength)
|
126
|
+
|
127
|
+
raise "No name given to the Web::input()-method." if !args[:name] and args[:type] != :info and args[:type] != :textshow and args[:type] != :plain and args[:type] != :spacer and args[:type] != :headline
|
128
|
+
|
129
|
+
css = {}
|
130
|
+
css["text-align"] = args[:align] if args.key?(:align)
|
131
|
+
css.merge!(args[:css]) if args.key?(:css)
|
132
|
+
|
133
|
+
attr_keys = [:onchange]
|
134
|
+
attr_keys.each do |tag|
|
135
|
+
if args.key?(tag)
|
136
|
+
attr[tag] = args[tag]
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
classes_tr = []
|
141
|
+
classes_tr += args[:classes_tr] if args[:classes_tr]
|
142
|
+
|
143
|
+
tr_attrs = {}
|
144
|
+
label_attrs = {}
|
145
|
+
td_attrs = {
|
146
|
+
:class => :tdc
|
147
|
+
}
|
148
|
+
|
149
|
+
if !args[:id].to_s.empty?
|
150
|
+
tr_attrs[:id] = "#{args[:id]}_tr"
|
151
|
+
td_attrs[:id] = "#{args[:id]}_content"
|
152
|
+
label_attrs[:for] = args[:id]
|
153
|
+
end
|
154
|
+
|
155
|
+
if !classes_tr.empty?
|
156
|
+
classes_tr_html = " class=\"#{classes_tr.join(" ")}\""
|
157
|
+
else
|
158
|
+
classes_tr_html = ""
|
159
|
+
end
|
160
|
+
|
161
|
+
if args.key?(:title)
|
162
|
+
title_html = html_escape(args[:title])
|
163
|
+
elsif args.key?(:title_html)
|
164
|
+
title_html = args[:title_html]
|
165
|
+
end
|
166
|
+
|
167
|
+
html = ""
|
168
|
+
|
169
|
+
classes = ["input_#{args[:type]}"]
|
170
|
+
classes = classes | args[:classes] if args.key?(:classes)
|
171
|
+
attr["class"] = classes.join(" ")
|
172
|
+
|
173
|
+
if args[:type] == :checkbox
|
174
|
+
attr["value"] = args[:value_active] if args.key?(:value_active)
|
175
|
+
attr["checked"] = "checked" if value.is_a?(String) and value == "1" or value.to_s == "1" or value.to_s == "on" or value.to_s == "true"
|
176
|
+
attr["checked"] = "checked" if value.is_a?(TrueClass)
|
177
|
+
|
178
|
+
html << "<tr#{classes_tr_html}>"
|
179
|
+
html << "<td colspan=\"2\" class=\"tdcheck\">"
|
180
|
+
html << "<input#{self.attr_html(attr)} />"
|
181
|
+
html << "<label#{attr_html(label_attrs)}\">#{title_html}</label>"
|
182
|
+
html << "</td>"
|
183
|
+
html << "</tr>"
|
184
|
+
elsif args[:type] == :headline
|
185
|
+
html << "<tr#{classes_tr_html}><td colspan=\"2\"><h2 class=\"input_headline\">#{title_html}</h2></td></tr>"
|
186
|
+
elsif args[:type] == :spacer
|
187
|
+
html << "<tr#{classes_tr_html}><td colspan=\"2\"> </td></tr>"
|
188
|
+
else
|
189
|
+
html << "<tr#{classes_tr_html}#{attr_html(tr_attrs)}>"
|
190
|
+
html << "<td class=\"tdt\" id=\"#{html_escape("#{args[:id]}_label")}\"><div>"
|
191
|
+
html << title_html
|
192
|
+
html << "</div></td>"
|
193
|
+
html << "<td#{self.style_html(css)}#{attr_html(td_attrs)}><div>"
|
194
|
+
|
195
|
+
if args[:type] == :textarea
|
196
|
+
if args.key?(:height)
|
197
|
+
if (Float(args[:height]) rescue false)
|
198
|
+
css["height"] = "#{args[:height]}px"
|
199
|
+
else
|
200
|
+
css["height"] = args[:height]
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
attr["class"] = "input_textarea"
|
205
|
+
attr["name" ] = args[:name]
|
206
|
+
attr["id"] = args[:id]
|
207
|
+
attr.delete("type")
|
208
|
+
|
209
|
+
html << "<textarea#{self.style_html(css)}#{self.attr_html(attr)}>#{value}</textarea>"
|
210
|
+
elsif args[:type] == :fckeditor
|
211
|
+
args[:height] = 400 if !args[:height]
|
212
|
+
|
213
|
+
require "/usr/share/fckeditor/fckeditor.rb" if !Kernel.const_defined?(:FCKeditor)
|
214
|
+
fck = FCKeditor.new(args[:name])
|
215
|
+
fck.Height = args[:height].to_i
|
216
|
+
fck.Value = value
|
217
|
+
html << fck.CreateHtml
|
218
|
+
elsif args[:type] == :ckeditor
|
219
|
+
args[:height] = 400 if !args[:height]
|
220
|
+
require "ckeditor4ruby" if !Kernel.const_defined?(:CKEditor)
|
221
|
+
ck = CKEditor.new
|
222
|
+
ck.return_output = true
|
223
|
+
html << ck.editor(args[:name], value)
|
224
|
+
elsif args[:type] == :select
|
225
|
+
attr[:multiple] = "multiple" if args[:multiple]
|
226
|
+
attr[:size] = args[:size] if args[:size]
|
227
|
+
|
228
|
+
html << "<select#{self.attr_html(attr)}>"
|
229
|
+
html << ArgsHandler.opts(args[:opts], value, args[:opts_args])
|
230
|
+
html << "</select>"
|
231
|
+
|
232
|
+
if args[:moveable]
|
233
|
+
html << "<div style=\"padding-top: 3px;\">"
|
234
|
+
html << "<input type=\"button\" value=\"#{_("Up")}\" onclick=\"select_moveup($('##{args[:id]}'));\" />"
|
235
|
+
html << "<input type=\"button\" value=\"#{_("Down")}\" onclick=\"select_movedown($('##{args[:id]}'));\" />"
|
236
|
+
html << "</div>"
|
237
|
+
end
|
238
|
+
elsif args[:type] == :imageupload
|
239
|
+
html << "<table class=\"designtable\"><tr#{classes_tr_html}><td style=\"width: 100%;\">"
|
240
|
+
html << "<input type=\"file\" name=\"#{args[:name].html}\" class=\"input_file\" />"
|
241
|
+
html << "</td><td style=\"padding-left: 5px;\">"
|
242
|
+
|
243
|
+
raise "No path given for imageupload-input." if !args.key?(:path)
|
244
|
+
raise "No value given in arguments for imageupload-input." if !args.key?(:value)
|
245
|
+
|
246
|
+
path = args[:path].gsub("%value%", value.to_s).untaint
|
247
|
+
if File.exists?(path)
|
248
|
+
html << "<img src=\"image.rhtml?path=#{html_escape(self.urlenc(path))}&smartsize=100&rounded_corners=10&border_color=black&force=true&ts=#{Time.new.to_f}\" alt=\"Image\" />"
|
249
|
+
|
250
|
+
if args[:dellink]
|
251
|
+
dellink = args[:dellink].gsub("%value%", value.to_s)
|
252
|
+
html << "<div style=\"text-align: center;\">(<a href=\"javascript: if (confirm('#{_("Do you want to delete the image?")}')){location.href='#{dellink}';}\">#{_("delete")}</a>)</div>"
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
html << "</td></tr></table>"
|
257
|
+
elsif args[:type] == :file
|
258
|
+
attr["type"] = args[:type]
|
259
|
+
attr["class"] = "input_#{args[:type]}"
|
260
|
+
attr["name"] = args[:name]
|
261
|
+
|
262
|
+
html << "<input#{self.attr_html(attr)} />"
|
263
|
+
elsif args[:type] == :textshow or args[:type] == :info
|
264
|
+
html << value.to_s
|
265
|
+
elsif args[:type] == :plain
|
266
|
+
html << "#{Php4r.nl2br(html_escape(value))}"
|
267
|
+
elsif args[:type] == :editarea
|
268
|
+
css["width"] = "100%"
|
269
|
+
css["height"] = args[:height] if args.key?(:height)
|
270
|
+
|
271
|
+
attr["id"] = args[:id]
|
272
|
+
attr["name"] = args[:name]
|
273
|
+
|
274
|
+
html << "<textarea#{self.attr_html(attr)}#{self.style_html(css)}>#{value}</textarea>"
|
275
|
+
|
276
|
+
jshash = {
|
277
|
+
"id" => args[:id],
|
278
|
+
"start_highlight" => true
|
279
|
+
}
|
280
|
+
|
281
|
+
pos_keys = [:skip_init, :allow_toggle, :replace_tab_by_spaces, :toolbar, :syntax]
|
282
|
+
pos_keys.each do |key|
|
283
|
+
jshash[key.to_s] = args[key] if args.key?(key)
|
284
|
+
end
|
285
|
+
|
286
|
+
html << "<script type=\"text/javascript\">"
|
287
|
+
html << "function knj_web_init_#{args[:name]}(){"
|
288
|
+
html << "editAreaLoader.init(#{Php4r.json_encode(jshash)});"
|
289
|
+
html << "}"
|
290
|
+
html << "</script>"
|
291
|
+
elsif args[:type] == :numeric
|
292
|
+
attr[:type] = :text
|
293
|
+
attr[:value] = value
|
294
|
+
html << "<input#{self.attr_html(attr)} />"
|
295
|
+
else
|
296
|
+
attr[:value] = value
|
297
|
+
html << "<input#{self.attr_html(attr)} />"
|
298
|
+
end
|
299
|
+
|
300
|
+
html << "</div></td></tr>"
|
301
|
+
end
|
302
|
+
|
303
|
+
html << "<tr#{classes_tr_html}><td colspan=\"2\" class=\"tdd\">#{args[:descr]}</td></tr>" if args[:descr]
|
304
|
+
return html
|
305
|
+
end
|
306
|
+
|
307
|
+
def self.opts(opthash, curvalue = nil, opts_args = {})
|
308
|
+
opts_args = {} if !opts_args
|
309
|
+
|
310
|
+
return "" if !opthash
|
311
|
+
cname = curvalue.class.name
|
312
|
+
curvalue = curvalue.id if (cname == "Knj::Db_row" or cname == "Knj::Datarow" or cname == "Baza::Model" or cname == "Baza::ModelCustom")
|
313
|
+
|
314
|
+
html = ""
|
315
|
+
addsel = " selected=\"selected\"" if !curvalue
|
316
|
+
|
317
|
+
html << "<option#{addsel} value=\"\">#{_("Add new")}</option>" if opts_args and (opts_args[:add] or opts_args[:addnew])
|
318
|
+
html << "<option#{addsel} value=\"\">#{_("Choose")}</option>" if opts_args and opts_args[:choose]
|
319
|
+
html << "<option#{addsel} value=\"\">#{_("None")}</option>" if opts_args and opts_args[:none]
|
320
|
+
html << "<option#{addsel} value=\"\">#{_("All")}</option>" if opts_args and opts_args[:all]
|
321
|
+
|
322
|
+
if opthash.is_a?(Hash) or opthash.class.to_s == "Dictionary"
|
323
|
+
opthash.each do |key, value|
|
324
|
+
html << "<option"
|
325
|
+
sel = false
|
326
|
+
|
327
|
+
if curvalue.is_a?(Array) and curvalue.index(key) != nil
|
328
|
+
sel = true
|
329
|
+
elsif curvalue.to_s == key.to_s
|
330
|
+
sel = true
|
331
|
+
elsif curvalue and curvalue.respond_to?(:is_knj?) and curvalue.id.to_s == key.to_s
|
332
|
+
sel = true
|
333
|
+
end
|
334
|
+
|
335
|
+
html << " selected=\"selected\"" if sel
|
336
|
+
html << " value=\"#{html_escape(key)}\">#{html_escape(value)}</option>"
|
337
|
+
end
|
338
|
+
elsif opthash.is_a?(Array)
|
339
|
+
opthash.each_index do |key|
|
340
|
+
if opthash[key.to_i] != nil
|
341
|
+
html << "<option"
|
342
|
+
html << " selected=\"selected\"" if curvalue.to_s == key.to_s
|
343
|
+
html << " value=\"#{html_escape(key)}\">#{html_escape(opthash[key])}</option>"
|
344
|
+
end
|
345
|
+
end
|
346
|
+
end
|
347
|
+
|
348
|
+
return html
|
349
|
+
end
|
350
|
+
|
351
|
+
def self.html_escape(str)
|
352
|
+
str = str.to_s
|
353
|
+
|
354
|
+
if Kernel.const_defined?("CGI")
|
355
|
+
return CGI.escape(str)
|
356
|
+
elsif Kernel.const_defined?("Knj")
|
357
|
+
return Knj::Web.html(str)
|
358
|
+
else
|
359
|
+
raise "Dont know how to HTML-escape string..."
|
360
|
+
end
|
361
|
+
end
|
362
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "ArgsHandler" do
|
4
|
+
it "should be able to execute various forms of Web.input methods." do
|
5
|
+
html = ArgsHandler.inputs([{
|
6
|
+
:title => "Test 1",
|
7
|
+
:name => :textest1,
|
8
|
+
:type => :text,
|
9
|
+
:default => "hmm",
|
10
|
+
:value => "trala"
|
11
|
+
},{
|
12
|
+
:title => "Test 2",
|
13
|
+
:name => :chetest2,
|
14
|
+
:type => :checkbox,
|
15
|
+
:default => true
|
16
|
+
},{
|
17
|
+
:title => "Test 4",
|
18
|
+
:name => :textest4,
|
19
|
+
:type => :textarea,
|
20
|
+
:height => 300,
|
21
|
+
:default => "Hmm",
|
22
|
+
:value => "Trala"
|
23
|
+
},{
|
24
|
+
:title => "Test 5",
|
25
|
+
:name => :filetest5,
|
26
|
+
:type => :file
|
27
|
+
},{
|
28
|
+
:title => "Test 6",
|
29
|
+
:type => :info,
|
30
|
+
:value => "Argh"
|
31
|
+
}])
|
32
|
+
|
33
|
+
puts html
|
34
|
+
end
|
35
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'args-handler'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: args-handler
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- kaspernj
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-04-24 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
version_requirements: !ruby/object:Gem::Requirement
|
16
|
+
none: false
|
17
|
+
requirements:
|
18
|
+
- - ! '>='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
name: knjrbfw
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
requirement: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
version_requirements: !ruby/object:Gem::Requirement
|
32
|
+
none: false
|
33
|
+
requirements:
|
34
|
+
- - ! '>='
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
name: php4r
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
requirement: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
version_requirements: !ruby/object:Gem::Requirement
|
48
|
+
none: false
|
49
|
+
requirements:
|
50
|
+
- - ~>
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 2.8.0
|
53
|
+
name: rspec
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.8.0
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.12'
|
69
|
+
name: rdoc
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '3.12'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ! '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: 1.0.0
|
85
|
+
name: bundler
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
requirement: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 1.0.0
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
version_requirements: !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ~>
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: 1.8.4
|
101
|
+
name: jeweler
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
requirement: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ~>
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 1.8.4
|
110
|
+
description: A small library to generate HTML for wished arguments form hashes.
|
111
|
+
email: k@spernj.org
|
112
|
+
executables: []
|
113
|
+
extensions: []
|
114
|
+
extra_rdoc_files:
|
115
|
+
- LICENSE.txt
|
116
|
+
- README.rdoc
|
117
|
+
files:
|
118
|
+
- .document
|
119
|
+
- .rspec
|
120
|
+
- Gemfile
|
121
|
+
- Gemfile.lock
|
122
|
+
- LICENSE.txt
|
123
|
+
- README.rdoc
|
124
|
+
- Rakefile
|
125
|
+
- VERSION
|
126
|
+
- lib/args-handler.rb
|
127
|
+
- spec/args-handler_spec.rb
|
128
|
+
- spec/spec_helper.rb
|
129
|
+
homepage: http://github.com/kaspernj/args-handler
|
130
|
+
licenses:
|
131
|
+
- MIT
|
132
|
+
post_install_message:
|
133
|
+
rdoc_options: []
|
134
|
+
require_paths:
|
135
|
+
- lib
|
136
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
segments:
|
142
|
+
- 0
|
143
|
+
hash: 609089676889269315
|
144
|
+
version: '0'
|
145
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
146
|
+
none: false
|
147
|
+
requirements:
|
148
|
+
- - ! '>='
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: '0'
|
151
|
+
requirements: []
|
152
|
+
rubyforge_project:
|
153
|
+
rubygems_version: 1.8.23
|
154
|
+
signing_key:
|
155
|
+
specification_version: 3
|
156
|
+
summary: A small library to generate HTML for wished arguments form hashes.
|
157
|
+
test_files: []
|