kiss 1.1 → 1.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/LICENSE +1 -1
  2. data/Rakefile +2 -1
  3. data/VERSION +1 -1
  4. data/bin/kiss +151 -34
  5. data/data/scaffold.tgz +0 -0
  6. data/lib/kiss.rb +389 -742
  7. data/lib/kiss/accessors/controller.rb +47 -0
  8. data/lib/kiss/accessors/request.rb +106 -0
  9. data/lib/kiss/accessors/template.rb +23 -0
  10. data/lib/kiss/action.rb +502 -132
  11. data/lib/kiss/bench.rb +14 -5
  12. data/lib/kiss/debug.rb +14 -6
  13. data/lib/kiss/exception_report.rb +22 -299
  14. data/lib/kiss/ext/core.rb +700 -0
  15. data/lib/kiss/ext/rack.rb +33 -0
  16. data/lib/kiss/ext/sequel_database.rb +47 -0
  17. data/lib/kiss/ext/sequel_mysql_dataset.rb +23 -0
  18. data/lib/kiss/form.rb +404 -179
  19. data/lib/kiss/form/field.rb +183 -307
  20. data/lib/kiss/form/field_types.rb +239 -0
  21. data/lib/kiss/format.rb +88 -70
  22. data/lib/kiss/html/exception_report.css +222 -0
  23. data/lib/kiss/html/exception_report.html +210 -0
  24. data/lib/kiss/iterator.rb +14 -12
  25. data/lib/kiss/login.rb +8 -8
  26. data/lib/kiss/mailer.rb +68 -66
  27. data/lib/kiss/model.rb +323 -36
  28. data/lib/kiss/rack/bench.rb +16 -8
  29. data/lib/kiss/rack/email_errors.rb +25 -15
  30. data/lib/kiss/rack/errors_ok.rb +2 -2
  31. data/lib/kiss/rack/facebook.rb +6 -6
  32. data/lib/kiss/rack/file_not_found.rb +10 -8
  33. data/lib/kiss/rack/log_exceptions.rb +3 -3
  34. data/lib/kiss/rack/recorder.rb +2 -2
  35. data/lib/kiss/rack/show_debug.rb +2 -2
  36. data/lib/kiss/rack/show_exceptions.rb +2 -2
  37. data/lib/kiss/request.rb +435 -0
  38. data/lib/kiss/sequel_session.rb +15 -14
  39. data/lib/kiss/static_file.rb +20 -13
  40. data/lib/kiss/template.rb +327 -0
  41. metadata +60 -25
  42. data/lib/kiss/controller_accessors.rb +0 -81
  43. data/lib/kiss/hacks.rb +0 -188
  44. data/lib/kiss/sequel_mysql.rb +0 -25
  45. data/lib/kiss/template_methods.rb +0 -167
@@ -1,167 +0,0 @@
1
- class Kiss
2
- module TemplateMethods
3
- include Kiss::ControllerAccessors
4
-
5
- def db
6
- controller.database
7
- end
8
- alias_method :database, :db
9
-
10
- # Contains data set by action/mailer logic to be displayed in templates.
11
- def data
12
- @data
13
- end
14
- alias_method :vars, :data
15
-
16
- def data=(hash)
17
- @data = hash
18
- end
19
- alias_method :'vars=', :'data='
20
-
21
- # Merges specified data (key-value pairs) into template data hash.
22
- def set(vars)
23
- vars.each_pair do |key,value|
24
- # convert symbols to strings
25
- @data[key] = value
26
- end
27
- end
28
-
29
- # Shorthand to access vars.title, here for backward compatibility.
30
- # Note: @title is deprecated for use in templates and will not be
31
- # supported in Kiss 1.0. Use title and title= instead.
32
- def title
33
- vars.title
34
- end
35
-
36
- # Shorthand to set vars.title, here for backward compatibility.
37
- # Note: @title is deprecated for use in templates and will not be
38
- # supported in Kiss 1.0. Use title and title= instead.
39
- def title=(new_title)
40
- vars.title = new_title
41
- @title = new_title
42
- end
43
-
44
- # Returns value of next layout file, which will be used to wrap the
45
- # results of current rendering template.
46
- # Note: @layout is deprecated for use in templates and will not be
47
- # supported in Kiss 1.0. Use layout and layout= instead.
48
- def layout
49
- # @layout deprecated; future will be action.layout
50
- @layout
51
- end
52
-
53
- # Sets path to next layout file, which will be used to wrap the
54
- # results of current rendering template.
55
- # Note: @layout is deprecated for use in templates and will not be
56
- # supported in Kiss 1.0. Use layout and layout= instead.
57
- def layout=(new_layout)
58
- # @layout deprecated; future will be action.layout
59
- @layout = new_layout
60
- end
61
-
62
- # Reads file specified by options and return contents (without template
63
- # processing).
64
- def insert(*args)
65
- path = get_template_path(get_template_options(*args))
66
- content = ::File.read(path)
67
- end
68
-
69
- # Processes template specified by options and return results.
70
- def process(*args)
71
- options = get_template_options(*args)
72
- path = get_template_path(options)
73
-
74
- if (options[:data] || options[:vars])
75
- new_data = (options[:data] || {}).merge(options[:vars] || {})
76
- old_data = self.data
77
- self.data = self.data.merge(new_data)
78
- else
79
- old_data = nil
80
- end
81
-
82
- content = erubis(path)
83
- self.data = old_data if old_data
84
-
85
- content
86
- end
87
- alias_method :process_template, :process
88
-
89
- # Convert arguments into options hash for use get_template_path.
90
- def get_template_options(*args)
91
- case args.length
92
- when 0
93
- {}
94
- when 1
95
- args[0].is_a?(Hash) ? args[0] : { :template => args[0] }
96
- when 2
97
- args[1].merge( :template => args[0] )
98
- else
99
- raise 'too many arguments'
100
- end
101
- end
102
-
103
- # Gets path to insert/template file from specified options.
104
- def get_template_path(options = {})
105
- @current_template_dir ||= @template_dir + action_subdir
106
-
107
- path = options[:template]
108
- extension = options[:extension]
109
-
110
- path += ".#{extension || 'rhtml'}" unless path =~ /\./
111
- (path =~ /\A\//) ? "#{@template_dir}#{path}" : "#{@current_template_dir}/#{path}"
112
- end
113
-
114
- # Processes specified template file using specified binding.
115
- # content is used to pass previously rendered results into
116
- # wrapper templates such as layouts.
117
- def erubis(path,template_binding = binding,content = nil)
118
- # params note: content (if provided) is passed to erubis template via binding
119
-
120
- # set template dir to dir that contains this template
121
- @current_template_dir ||= @template_dir
122
- old_template_dir = @current_template_dir
123
- @current_template_dir = path.sub(/\/?[^\/]*\Z/,'')
124
-
125
- # read the file, parse into eruby source,
126
- # and pre-process source for Kiss additions
127
- eruby_src = file_cache(path) do |template|
128
- template ? begin
129
- # macros
130
- template.gsub!(/\<\%\s*macro\s+(\w+.*?)\s*\%\>/,'<% def \1; _buf = \'\' %>')
131
- template.gsub!(/\<\%\s*end\s+macro\s*\%\>/,'<% _buf; end %>')
132
-
133
- # generic loop iterator, using 'iterate'
134
- template.gsub!(/\<\%\s*iterate\s+(\w+)\s+(.*?)\s*\%\>/,"<% \\1 = Kiss::Iterator.new; \\2; \\1.increment %>")
135
- # for loop iterator
136
- template.gsub!(/\<\%\s*for\s+(\w+)\s+in\s+(.*?)\s*\%\>/,"<% \\1_loop = Kiss::Iterator.new(\\2); for \\1 in \\1_loop.collection; \\1_loop.increment %>")
137
-
138
- Erubis::Eruby.new(template).src
139
- end : nil
140
- end
141
- raise Kiss::FileNotFound, "template '#{path}' not found" unless eruby_src
142
-
143
- # evaluate source in context of template_binding
144
- result = eval eruby_src, template_binding, path
145
-
146
- # restore previous template dir
147
- @current_template_dir = old_template_dir
148
-
149
- result
150
- end
151
-
152
- # Escapes string for use in URLs.
153
- def url_escape(string)
154
- Kiss.url_escape(str)
155
- end
156
- alias_method :escape, :url_escape
157
- alias_method :url_encode, :url_escape
158
- alias_method :escape_url, :url_escape
159
-
160
- # Encodes string for output to HTML.
161
- def html_escape(str)
162
- Kiss.html_escape(str)
163
- end
164
- alias_method :h, :html_escape
165
- alias_method :escape_html, :html_escape
166
- end
167
- end