slippers 0.0.10
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.
- data/LICENSE +20 -0
- data/README +56 -0
- data/Rakefile +27 -0
- data/VERSION.yml +4 -0
- data/examples/blog/README +3 -0
- data/examples/blog/blog.db +0 -0
- data/examples/blog/controller/main.rb +30 -0
- data/examples/blog/model/entry.rb +31 -0
- data/examples/blog/public/styles/blog.css +132 -0
- data/examples/blog/spec/blog.rb +87 -0
- data/examples/blog/start.rb +7 -0
- data/examples/blog/view/edit.st +19 -0
- data/examples/blog/view/edit.xhtml +17 -0
- data/examples/blog/view/entry.st +12 -0
- data/examples/blog/view/index.st +4 -0
- data/examples/blog/view/index.xhtml +17 -0
- data/examples/blog/view/layout.st +11 -0
- data/examples/blog/view/layout.xhtml +11 -0
- data/examples/blog/view/new.st +16 -0
- data/examples/blog/view/new.xhtml +16 -0
- data/examples/forms/Rakefile +22 -0
- data/examples/forms/controller/init.rb +12 -0
- data/examples/forms/controller/main.rb +20 -0
- data/examples/forms/controller/registration.rb +24 -0
- data/examples/forms/forms.db +0 -0
- data/examples/forms/model/core_extensions/string_extensions.rb +5 -0
- data/examples/forms/model/field.rb +33 -0
- data/examples/forms/model/form.rb +33 -0
- data/examples/forms/model/init.rb +18 -0
- data/examples/forms/model/orm/registration.rb +12 -0
- data/examples/forms/model/registration_form_builder.rb +7 -0
- data/examples/forms/model/registration_repository.rb +39 -0
- data/examples/forms/model/registration_rules/incorrect_email_format.rb +11 -0
- data/examples/forms/model/registration_rules/number_field.rb +10 -0
- data/examples/forms/model/registration_rules/required_field.rb +9 -0
- data/examples/forms/model/registration_validator.rb +17 -0
- data/examples/forms/public/css/ramaze_error.css +90 -0
- data/examples/forms/public/dispatch.fcgi +11 -0
- data/examples/forms/public/favicon.ico +0 -0
- data/examples/forms/public/js/jquery.js +3549 -0
- data/examples/forms/public/ramaze.png +0 -0
- data/examples/forms/public/web-application.js +0 -0
- data/examples/forms/spec/form_spec.rb +16 -0
- data/examples/forms/spec/main.rb +25 -0
- data/examples/forms/spec/registration_controller_spec.rb +0 -0
- data/examples/forms/spec/registration_repository_spec.rb +38 -0
- data/examples/forms/spec/registration_validator_spec.rb +53 -0
- data/examples/forms/spec/spec_helper.rb +3 -0
- data/examples/forms/start.rb +12 -0
- data/examples/forms/start.ru +16 -0
- data/examples/forms/view/error.xhtml +64 -0
- data/examples/forms/view/index.xhtml +34 -0
- data/examples/forms/view/page.xhtml +27 -0
- data/examples/forms/view/registration/index.st +26 -0
- data/examples/main_controller.rb +40 -0
- data/examples/start.rb +7 -0
- data/examples/todolist/README +1 -0
- data/examples/todolist/controller/main.rb +71 -0
- data/examples/todolist/layout/page.rb +31 -0
- data/examples/todolist/model/tasks.rb +14 -0
- data/examples/todolist/public/favicon.ico +0 -0
- data/examples/todolist/public/js/jquery.js +1923 -0
- data/examples/todolist/public/ramaze.png +0 -0
- data/examples/todolist/start.rb +11 -0
- data/examples/todolist/todolist.db +11 -0
- data/examples/todolist/view/index.st +39 -0
- data/examples/todolist/view/index.xhtml +17 -0
- data/examples/todolist/view/new.st +41 -0
- data/examples/todolist/view/new.xhtml +7 -0
- data/examples/todolist/view/tasks.st +6 -0
- data/examples/todolist.db +5 -0
- data/examples/view/index.st +11 -0
- data/examples/view/person/age.st +1 -0
- data/examples/view/person/age_renderer.rb +6 -0
- data/examples/view/person/index.st +2 -0
- data/lib/engine/binding_wrapper.rb +10 -0
- data/lib/engine/engine.rb +28 -0
- data/lib/engine/file_template.rb +12 -0
- data/lib/engine/slippers.treetop +169 -0
- data/lib/engine/slippers_nodes.rb +119 -0
- data/lib/engine/template.rb +17 -0
- data/lib/engine/template_group.rb +40 -0
- data/lib/engine/template_group_directory.rb +57 -0
- data/lib/ramazeTemplates/0001-Adding-slippers-as-a-new-template.patch +138 -0
- data/lib/ramazeTemplates/0002-Fixing-problem-with-using-other-renderers.patch +27 -0
- data/lib/ramazeTemplates/slippers.rb +22 -0
- data/lib/slippers.rb +14 -0
- data/spec/binding_wrapper.rb +19 -0
- data/spec/engine.rb +89 -0
- data/spec/file_template.rb +9 -0
- data/spec/parse_attributes.rb +98 -0
- data/spec/parse_renderers.rb +35 -0
- data/spec/parse_templates.rb +73 -0
- data/spec/person_template.st +1 -0
- data/spec/spec_helper.rb +14 -0
- data/spec/template_group.rb +52 -0
- data/spec/template_group_directory.rb +43 -0
- data/spec/views/index.st +1 -0
- data/spec/views/money.rb +2 -0
- data/spec/views/person/age.st +1 -0
- data/spec/views/person/date_renderer.rb +5 -0
- data/spec/views/person/name.st +1 -0
- metadata +218 -0
@@ -0,0 +1,33 @@
|
|
1
|
+
class Form
|
2
|
+
|
3
|
+
def initialize(key_default_pairs={})
|
4
|
+
@fields = []
|
5
|
+
key_default_pairs.each {|key,value| @fields << Field.new(key, value)}
|
6
|
+
end
|
7
|
+
|
8
|
+
def update(new_values)
|
9
|
+
new_values.each { | key,value | find(key).update(value)}
|
10
|
+
end
|
11
|
+
|
12
|
+
def [](field)
|
13
|
+
find(field).value
|
14
|
+
end
|
15
|
+
|
16
|
+
def is_valid?
|
17
|
+
@fields.all? { |field| field.is_valid? }
|
18
|
+
end
|
19
|
+
|
20
|
+
def invalid(key, error)
|
21
|
+
find(key).invalid(error)
|
22
|
+
end
|
23
|
+
|
24
|
+
def errors_for(key)
|
25
|
+
find(key).errors
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def find(key)
|
31
|
+
@fields.find { | field | field.is?(key)}
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# Here goes your database connection and options:
|
2
|
+
require 'sequel'
|
3
|
+
Sequel::Model.plugin(:schema)
|
4
|
+
DB = Sequel.sqlite('forms.db')
|
5
|
+
|
6
|
+
# Here go your requires for models:
|
7
|
+
# require 'model/user'
|
8
|
+
require 'model/orm/registration'
|
9
|
+
require 'model/registration_form_builder'
|
10
|
+
require 'model/registration_repository'
|
11
|
+
require 'model/registration_validator'
|
12
|
+
require 'model/registration_rules/required_field'
|
13
|
+
require 'model/registration_rules/number_field'
|
14
|
+
require 'model/registration_rules/incorrect_email_format'
|
15
|
+
require 'model/form'
|
16
|
+
require 'model/field'
|
17
|
+
require 'model/core_extensions/string_extensions'
|
18
|
+
|
@@ -0,0 +1,39 @@
|
|
1
|
+
class RegistrationRepository
|
2
|
+
|
3
|
+
def find(key=rand(100))
|
4
|
+
form = RegistrationFormBuilder.new.build(key)
|
5
|
+
registration = find_registration(key)
|
6
|
+
return form unless registration
|
7
|
+
update_form(form, registration)
|
8
|
+
end
|
9
|
+
|
10
|
+
def save(form)
|
11
|
+
registration = find_registration(form[:key])
|
12
|
+
registration = create_registration unless registration
|
13
|
+
update_registration(registration, form)
|
14
|
+
registration.save
|
15
|
+
form.update(:key => registration.id)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def find_registration(key)
|
21
|
+
registration = Registration[:id => key]
|
22
|
+
end
|
23
|
+
|
24
|
+
def create_registration
|
25
|
+
registration = Registration.new
|
26
|
+
registration
|
27
|
+
end
|
28
|
+
|
29
|
+
def update_form(form, registration)
|
30
|
+
form.update(:name => registration.name, :address => registration.address, :email => registration.email)
|
31
|
+
form
|
32
|
+
end
|
33
|
+
|
34
|
+
def update_registration(registration, form)
|
35
|
+
registration.name = form[:name]
|
36
|
+
registration.address = form[:address]
|
37
|
+
registration.email = form[:email]
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class RegistrationValidator
|
2
|
+
|
3
|
+
def initialize
|
4
|
+
@rules = {
|
5
|
+
:name => [RequiredField.new],
|
6
|
+
:email => [RequiredField.new, IncorrectEmailFormat.new],
|
7
|
+
:phone => [NumberField.new]
|
8
|
+
}
|
9
|
+
end
|
10
|
+
|
11
|
+
def validate(form)
|
12
|
+
@rules.each do |key, rules|
|
13
|
+
rules.each { |rule| rule.validate(form, key)}
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
body {
|
2
|
+
font-family: sans-serif;
|
3
|
+
}
|
4
|
+
|
5
|
+
h1.main {
|
6
|
+
text-align: center;
|
7
|
+
}
|
8
|
+
|
9
|
+
td {
|
10
|
+
padding: 4px;
|
11
|
+
}
|
12
|
+
|
13
|
+
table.main {
|
14
|
+
background: #444;
|
15
|
+
margin-left: 2em;
|
16
|
+
}
|
17
|
+
|
18
|
+
div.additional h3 {
|
19
|
+
cursor: pointer;
|
20
|
+
}
|
21
|
+
|
22
|
+
div.additional pre {
|
23
|
+
margin-left: 2em;
|
24
|
+
}
|
25
|
+
|
26
|
+
table.main tr.head {
|
27
|
+
background: #fee;
|
28
|
+
width: 100%;
|
29
|
+
}
|
30
|
+
|
31
|
+
table.main tr {
|
32
|
+
background: #fff;
|
33
|
+
}
|
34
|
+
|
35
|
+
table.main tr.source_container {
|
36
|
+
display: none;
|
37
|
+
}
|
38
|
+
|
39
|
+
tr.source td {
|
40
|
+
padding: 0;
|
41
|
+
}
|
42
|
+
|
43
|
+
tr.source_container div {
|
44
|
+
width: 100%;
|
45
|
+
overflow: auto;
|
46
|
+
}
|
47
|
+
|
48
|
+
tr.source_container div table {
|
49
|
+
background: #ddd;
|
50
|
+
width: 100%;
|
51
|
+
}
|
52
|
+
|
53
|
+
tr.source_container div table tr {
|
54
|
+
text-align:center;
|
55
|
+
}
|
56
|
+
|
57
|
+
tr.source_container div table tr.source {
|
58
|
+
text-align:left;
|
59
|
+
}
|
60
|
+
|
61
|
+
div.source {
|
62
|
+
background: #fff;
|
63
|
+
padding: 6px;
|
64
|
+
}
|
65
|
+
|
66
|
+
div.source td.editor {
|
67
|
+
font-size: 0.8em;
|
68
|
+
}
|
69
|
+
|
70
|
+
tr.source {
|
71
|
+
font-size: 1.0em;
|
72
|
+
}
|
73
|
+
|
74
|
+
tr.source td.lineno {
|
75
|
+
font-size: 0.9em;
|
76
|
+
font-family: monospace;
|
77
|
+
}
|
78
|
+
|
79
|
+
tr.source td.lineno, tr.line td.lineno {
|
80
|
+
text-align: right;
|
81
|
+
}
|
82
|
+
|
83
|
+
tr.line td {
|
84
|
+
cursor: pointer;
|
85
|
+
}
|
86
|
+
|
87
|
+
tr.source td.code pre {
|
88
|
+
margin: 0;
|
89
|
+
font-family: monospace;
|
90
|
+
}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'ramaze'
|
5
|
+
|
6
|
+
# FCGI doesn't like you writing to stdout
|
7
|
+
Ramaze::Log.loggers = [ Ramaze::Logger::Informer.new( __DIR__("../ramaze.fcgi.log") ) ]
|
8
|
+
Ramaze::Global.adapter = :fcgi
|
9
|
+
|
10
|
+
$0 = __DIR__("../start.rb")
|
11
|
+
require $0
|
Binary file
|