starapor-slippers 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README +9 -1
- data/VERSION.yml +2 -2
- 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/lib/engine/binding_wrapper.rb +1 -1
- data/spec/binding_wrapper.rb +5 -0
- data/spec/parser.rb +2 -0
- metadata +48 -3
data/README
CHANGED
@@ -32,4 +32,12 @@ Examples
|
|
32
32
|
5. Applying a new object to an anonymous subtemplate
|
33
33
|
template = "This is a template and then $message:{this is a subtemplate with a message of $saying$}$!"
|
34
34
|
engine = Slippers::Engine.new(template)
|
35
|
-
engine.render(:message => {:saying => 'hello world'})
|
35
|
+
engine.render(:message => {:saying => 'hello world'}) #=> "This is a template and then this is a subtemplate with a message of hello world!"
|
36
|
+
|
37
|
+
6. Render a subtemplate using a different rendering technology
|
38
|
+
age_renderer = AgeRenderer.new
|
39
|
+
subtemplate = Slippers::Engine.new('$first$ $last$')
|
40
|
+
person = OpenStruct.new({:name => {:first => 'Fred', :last => 'Flinstone'}, :dob => Date.new(DateTime.now.year - 34, 2, 4)})
|
41
|
+
template_group = Slippers::TemplateGroup.new(:templates => {:name => subtemplate, :age => age_renderer})
|
42
|
+
engine = Slippers::Engine.new("Introducing $name:name()$ who is $dob:age()$.", :template_group => template_group)
|
43
|
+
engine.render(person) #=> "Introducing Fred Flinstone who is 34 years old."
|
data/VERSION.yml
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'spec/rake/spectask'
|
3
|
+
|
4
|
+
desc "Run all examples"
|
5
|
+
Spec::Rake::SpecTask.new('examples') do |t|
|
6
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'spec/rake/spectask'
|
10
|
+
Spec::Rake::SpecTask.new(:spec) do |t|
|
11
|
+
t.libs << 'lib' << 'spec'
|
12
|
+
t.spec_files = FileList['spec/**/*.rb']
|
13
|
+
end
|
14
|
+
|
15
|
+
Spec::Rake::SpecTask.new(:rcov) do |t|
|
16
|
+
t.libs << 'lib' << 'spec'
|
17
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
18
|
+
t.rcov = true
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
task :default => :examples
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# Define a subclass of Ramaze::Controller holding your defaults for all
|
2
|
+
# controllers
|
3
|
+
|
4
|
+
class Controller < Ramaze::Controller
|
5
|
+
layout '/page'
|
6
|
+
helper :xhtml
|
7
|
+
engine :Slippers
|
8
|
+
end
|
9
|
+
|
10
|
+
# Here go your requires for subclasses of Controller:
|
11
|
+
require 'controller/main'
|
12
|
+
require 'controller/registration'
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# Default url mappings are:
|
2
|
+
# a controller called Main is mapped on the root of the site: /
|
3
|
+
# a controller called Something is mapped on: /something
|
4
|
+
# If you want to override this, add a line like this inside the class
|
5
|
+
# map '/otherurl'
|
6
|
+
# this will force the controller to be mounted on: /otherurl
|
7
|
+
|
8
|
+
class MainController < Controller
|
9
|
+
# the index action is called automatically when no other action is specified
|
10
|
+
def index
|
11
|
+
@title = "Welcome to Ramaze!"
|
12
|
+
end
|
13
|
+
|
14
|
+
# the string returned at the end of the function is used as the html body
|
15
|
+
# if there is no template for the action. if there is a template, the string
|
16
|
+
# is silently ignored
|
17
|
+
def notemplate
|
18
|
+
"there is no 'notemplate.xhtml' associated with this action"
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class RegistrationController < Controller
|
2
|
+
|
3
|
+
def initialize
|
4
|
+
@registrationRepository = RegistrationRepository.new
|
5
|
+
@registrationValidator = RegistrationValidator.new
|
6
|
+
end
|
7
|
+
def index
|
8
|
+
key = request[:key]
|
9
|
+
@form = @registrationRepository.find(key)
|
10
|
+
@message = if flash[:message] then flash[:message] else "" end
|
11
|
+
end
|
12
|
+
|
13
|
+
def save
|
14
|
+
key=request[:key]
|
15
|
+
form = @registrationRepository.find(key)
|
16
|
+
form.update(:name => request[:name], :address => request[:address], :email => request[:email], :phone => request[:phone])
|
17
|
+
|
18
|
+
@registrationValidator.validate(form)
|
19
|
+
|
20
|
+
@registrationRepository.save(form)
|
21
|
+
flash[:message] = "Saved!"
|
22
|
+
redirect R('/registration', :index, :key=>form[:key])
|
23
|
+
end
|
24
|
+
end
|
Binary file
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class Field
|
2
|
+
|
3
|
+
def initialize(key, value)
|
4
|
+
@key = key
|
5
|
+
@value = value
|
6
|
+
@errors = []
|
7
|
+
end
|
8
|
+
|
9
|
+
def update(value)
|
10
|
+
@value = value
|
11
|
+
end
|
12
|
+
|
13
|
+
def value
|
14
|
+
@value
|
15
|
+
end
|
16
|
+
|
17
|
+
def is?(key)
|
18
|
+
@key == key
|
19
|
+
end
|
20
|
+
|
21
|
+
def is_valid?
|
22
|
+
@errors.empty?
|
23
|
+
end
|
24
|
+
|
25
|
+
def invalid(error)
|
26
|
+
@errors << error
|
27
|
+
end
|
28
|
+
|
29
|
+
def errors
|
30
|
+
@errors
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -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
|