slippers 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. data/LICENSE +20 -0
  2. data/README +56 -0
  3. data/Rakefile +27 -0
  4. data/VERSION.yml +4 -0
  5. data/examples/blog/README +3 -0
  6. data/examples/blog/blog.db +0 -0
  7. data/examples/blog/controller/main.rb +30 -0
  8. data/examples/blog/model/entry.rb +31 -0
  9. data/examples/blog/public/styles/blog.css +132 -0
  10. data/examples/blog/spec/blog.rb +87 -0
  11. data/examples/blog/start.rb +7 -0
  12. data/examples/blog/view/edit.st +19 -0
  13. data/examples/blog/view/edit.xhtml +17 -0
  14. data/examples/blog/view/entry.st +12 -0
  15. data/examples/blog/view/index.st +4 -0
  16. data/examples/blog/view/index.xhtml +17 -0
  17. data/examples/blog/view/layout.st +11 -0
  18. data/examples/blog/view/layout.xhtml +11 -0
  19. data/examples/blog/view/new.st +16 -0
  20. data/examples/blog/view/new.xhtml +16 -0
  21. data/examples/forms/Rakefile +22 -0
  22. data/examples/forms/controller/init.rb +12 -0
  23. data/examples/forms/controller/main.rb +20 -0
  24. data/examples/forms/controller/registration.rb +24 -0
  25. data/examples/forms/forms.db +0 -0
  26. data/examples/forms/model/core_extensions/string_extensions.rb +5 -0
  27. data/examples/forms/model/field.rb +33 -0
  28. data/examples/forms/model/form.rb +33 -0
  29. data/examples/forms/model/init.rb +18 -0
  30. data/examples/forms/model/orm/registration.rb +12 -0
  31. data/examples/forms/model/registration_form_builder.rb +7 -0
  32. data/examples/forms/model/registration_repository.rb +39 -0
  33. data/examples/forms/model/registration_rules/incorrect_email_format.rb +11 -0
  34. data/examples/forms/model/registration_rules/number_field.rb +10 -0
  35. data/examples/forms/model/registration_rules/required_field.rb +9 -0
  36. data/examples/forms/model/registration_validator.rb +17 -0
  37. data/examples/forms/public/css/ramaze_error.css +90 -0
  38. data/examples/forms/public/dispatch.fcgi +11 -0
  39. data/examples/forms/public/favicon.ico +0 -0
  40. data/examples/forms/public/js/jquery.js +3549 -0
  41. data/examples/forms/public/ramaze.png +0 -0
  42. data/examples/forms/public/web-application.js +0 -0
  43. data/examples/forms/spec/form_spec.rb +16 -0
  44. data/examples/forms/spec/main.rb +25 -0
  45. data/examples/forms/spec/registration_controller_spec.rb +0 -0
  46. data/examples/forms/spec/registration_repository_spec.rb +38 -0
  47. data/examples/forms/spec/registration_validator_spec.rb +53 -0
  48. data/examples/forms/spec/spec_helper.rb +3 -0
  49. data/examples/forms/start.rb +12 -0
  50. data/examples/forms/start.ru +16 -0
  51. data/examples/forms/view/error.xhtml +64 -0
  52. data/examples/forms/view/index.xhtml +34 -0
  53. data/examples/forms/view/page.xhtml +27 -0
  54. data/examples/forms/view/registration/index.st +26 -0
  55. data/examples/main_controller.rb +40 -0
  56. data/examples/start.rb +7 -0
  57. data/examples/todolist/README +1 -0
  58. data/examples/todolist/controller/main.rb +71 -0
  59. data/examples/todolist/layout/page.rb +31 -0
  60. data/examples/todolist/model/tasks.rb +14 -0
  61. data/examples/todolist/public/favicon.ico +0 -0
  62. data/examples/todolist/public/js/jquery.js +1923 -0
  63. data/examples/todolist/public/ramaze.png +0 -0
  64. data/examples/todolist/start.rb +11 -0
  65. data/examples/todolist/todolist.db +11 -0
  66. data/examples/todolist/view/index.st +39 -0
  67. data/examples/todolist/view/index.xhtml +17 -0
  68. data/examples/todolist/view/new.st +41 -0
  69. data/examples/todolist/view/new.xhtml +7 -0
  70. data/examples/todolist/view/tasks.st +6 -0
  71. data/examples/todolist.db +5 -0
  72. data/examples/view/index.st +11 -0
  73. data/examples/view/person/age.st +1 -0
  74. data/examples/view/person/age_renderer.rb +6 -0
  75. data/examples/view/person/index.st +2 -0
  76. data/lib/engine/binding_wrapper.rb +10 -0
  77. data/lib/engine/engine.rb +28 -0
  78. data/lib/engine/file_template.rb +12 -0
  79. data/lib/engine/slippers.treetop +169 -0
  80. data/lib/engine/slippers_nodes.rb +119 -0
  81. data/lib/engine/template.rb +17 -0
  82. data/lib/engine/template_group.rb +40 -0
  83. data/lib/engine/template_group_directory.rb +57 -0
  84. data/lib/ramazeTemplates/0001-Adding-slippers-as-a-new-template.patch +138 -0
  85. data/lib/ramazeTemplates/0002-Fixing-problem-with-using-other-renderers.patch +27 -0
  86. data/lib/ramazeTemplates/slippers.rb +22 -0
  87. data/lib/slippers.rb +14 -0
  88. data/spec/binding_wrapper.rb +19 -0
  89. data/spec/engine.rb +89 -0
  90. data/spec/file_template.rb +9 -0
  91. data/spec/parse_attributes.rb +98 -0
  92. data/spec/parse_renderers.rb +35 -0
  93. data/spec/parse_templates.rb +73 -0
  94. data/spec/person_template.st +1 -0
  95. data/spec/spec_helper.rb +14 -0
  96. data/spec/template_group.rb +52 -0
  97. data/spec/template_group_directory.rb +43 -0
  98. data/spec/views/index.st +1 -0
  99. data/spec/views/money.rb +2 -0
  100. data/spec/views/person/age.st +1 -0
  101. data/spec/views/person/date_renderer.rb +5 -0
  102. data/spec/views/person/name.st +1 -0
  103. 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,12 @@
1
+ class Registration < Sequel::Model
2
+ set_schema do
3
+ primary_key :id
4
+
5
+ varchar :name
6
+ varchar :address
7
+ varchar :email
8
+ end
9
+
10
+ create_table unless table_exists?
11
+
12
+ end
@@ -0,0 +1,7 @@
1
+ class RegistrationFormBuilder
2
+
3
+ def build(key=nil)
4
+ Form.new(:key => key, :name => "", :address => "", :email => "", :phone => nil)
5
+ end
6
+
7
+ end
@@ -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,11 @@
1
+ class IncorrectEmailFormat
2
+ def validate(form, key)
3
+ return unless form[key]
4
+ return if form[key]['@']
5
+ form.invalid(key, IncorrectEmailFormatError.new)
6
+ end
7
+ end
8
+
9
+
10
+ class IncorrectEmailFormatError
11
+ end
@@ -0,0 +1,10 @@
1
+ class NumberField
2
+ def validate(form, key)
3
+ return unless form[key]
4
+ return if form[key].is_numeric?
5
+ form.invalid(key, NumberFieldError.new)
6
+ end
7
+ end
8
+
9
+ class NumberFieldError
10
+ end
@@ -0,0 +1,9 @@
1
+ class RequiredField
2
+ def validate(form, key)
3
+ return if form[key] and not( form[key].empty?)
4
+ form.invalid(key, RequiredFieldError.new)
5
+ end
6
+ end
7
+
8
+ class RequiredFieldError
9
+ 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