cuca 0.06 → 0.07

Sign up to get free protection for your applications and to get access to all the features.
@@ -17,6 +17,8 @@ require 'active_record'
17
17
  # :sortable = => [optional] true/false if columns can be sorted (default autodetect)
18
18
  # DBLIST specific is only :query
19
19
  class DBListWidget < BaseList
20
+ @@like_expression = 'LIKE'
21
+
20
22
  def columns
21
23
  # $stderr.puts " Getting Columns: #{@columns}"
22
24
  @columns.delete_if { |c| !c[:display] }
@@ -32,14 +34,19 @@ class DBListWidget < BaseList
32
34
  field_id
33
35
  end
34
36
 
37
+ def quote(input)
38
+ input.gsub(/\\/, '\&\&').gsub(/'/, "''")
39
+ end
40
+
35
41
  def where_clause(query_def)
42
+ like = @@like_expression || 'LIKE' # this allows to overwrite to ILIKE for example
36
43
  res = []
37
44
  query_def.filters.each_pair do |k,v|
38
45
  next if (v.nil? || v == '')
39
46
  if @model_class.columns_hash.include?(k) && @model_class.columns_hash[k].number? then
40
- res << "#{wc_query_field(k)} = #{v}"
47
+ res << "#{wc_query_field(k)} = #{v.to_i}"
41
48
  else
42
- res << "#{wc_query_field(k)} LIKE '%#{v}%'"
49
+ res << "#{wc_query_field(k)} #{like} '%#{quote(v)}%'"
43
50
  end
44
51
  end
45
52
  wc = "true"
@@ -79,15 +86,11 @@ class DBListWidget < BaseList
79
86
  ret
80
87
  end
81
88
  findstuff[:select] = sel.compact.join(',')
82
- $stderr.puts "Find-Stuff: #{findstuff.inspect}"
83
89
  @data = @model_class.find(:all, findstuff)
84
- $stderr.puts "data: #{@data}"
85
90
  @additional_data = @data.dup
86
91
 
87
92
  @data = normalize_result(@data)
88
93
  @total_rows= @model_class.count(:conditions => where_clause(query_def), :joins => @joins)
89
-
90
- # $stderr.puts "Query: #{@data.inspect} - #{query_def.order_by.inspect}"
91
94
  end
92
95
 
93
96
  def setup
@@ -115,6 +118,7 @@ class DBListWidget < BaseList
115
118
  @columns = data_setup[:columns] || []
116
119
  @extra_conditions = data_setup[:conditons] || ""
117
120
  @joins = data_setup[:joins] || ""
121
+ @options ||= data_setup[:options] # can be used by 'setup'
118
122
  @model_class = model_class || nil
119
123
  setup
120
124
  fixup_columns
@@ -103,6 +103,23 @@ class BaseList < Cuca::Widget
103
103
  view_p(erb_template)
104
104
  end # def
105
105
 
106
+ def list_size_links
107
+ r = []
108
+ [25,50,75,100,-1].each do |n_rows|
109
+ next if n_rows > @total_rows
110
+ next if n_rows == -1 && (@total_rows > 2000)
111
+ t = n_rows > 0 ? n_rows.to_s : 'all'
112
+ start = @query_def.range.first < n_rows ? 0 : @query_def.range.first
113
+ rows = n_rows > 0 ? n_rows : @total_rows * 2
114
+ if (@query_def.range.last - @query_def.range.first) == rows then
115
+ r << "<b>#{t}</b>"
116
+ else
117
+ r << "#{SLinkWidget.new(:args => ['',t,@query_def.to_h('range', (start..start+rows))] )}"
118
+ end
119
+ end
120
+ r.join(' ')
121
+ end
122
+
106
123
  private
107
124
  def paginate_links()
108
125
  @rows_per_page = (@query_def.range.last - @query_def.range.first) + 1
@@ -133,14 +150,14 @@ class BaseList < Cuca::Widget
133
150
  end
134
151
 
135
152
  return pl
136
-
137
153
  end
138
154
 
139
155
  private
140
156
  def erb_template
141
157
  <<'ENDTEMPLATE'
142
158
  <div class='list'>
143
- [ <%= @paginate %> ]
159
+ Pages: [ <%= @paginate %> ]
160
+ Rows: [<%= list_size_links %> ]
144
161
  <table width>
145
162
  <tr>
146
163
 
@@ -184,8 +201,11 @@ end
184
201
  <% @data.each_index do |row_idx| %>
185
202
  <tr>
186
203
  <% @data[row_idx].each_index do |field_idx| %>
187
- <% add_data = @additional_data[row_idx] || nil %>
188
- <td> <%= rewrite_field(@data[row_idx], @columns[field_idx][:id], @data[row_idx][field_idx], add_data) %> </td>
204
+ <% add_data = @additional_data[row_idx] || nil
205
+ cell_align = @columns[field_idx][:align]
206
+ align_line = cell_align ? " align='#{cell_align}'" : ''
207
+ %>
208
+ <td<%=align_line%>> <%= rewrite_field(@data[row_idx], @columns[field_idx][:id], @data[row_idx][field_idx], add_data) %> </td>
189
209
  <% end %>
190
210
  </tr>
191
211
  <% end %>
data/lib/cuca/widget.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Cuca
2
- # === Widget
2
+ # = Widget
3
3
  #
4
4
  # All elements that generate content (e.g. html) are widgets. To implement a widget create
5
5
  # a class derrived from Cuca::Widget and overwrite the +output+ method. The output method
@@ -7,11 +7,6 @@ module Cuca
7
7
  # should write your result to @_content. For this it is advisable to use the content accessor
8
8
  # or any of the Cuca::Generator 's.
9
9
  #
10
- # == Variables
11
- #
12
- # Instance variables shall be used by sub-widgets and generators. You can fetch them
13
- # with get_assigns.
14
- #
15
10
  # == Naming
16
11
  #
17
12
  # Name all widgets like YournameWidget - when using them in a generator simply call them
@@ -153,11 +148,12 @@ class Widget
153
148
  a = @_assigns.clone
154
149
 
155
150
  self.instance_variables.each do |v|
156
- next if v.match(/^\@\_/)
157
- next if v.include?('cancel_execution') # this is some internal key
158
- a[v.gsub(/\@/,'')] = self.instance_variable_get(v)
151
+ vs = v.to_s
152
+ next if vs.match(/^\@\_/)
153
+ next if vs.include?('cancel_execution') # this is some internal key
154
+ a[vs.gsub(/\@/,'')] = self.instance_variable_get(v)
159
155
  end
160
- return a
156
+ a
161
157
  end
162
158
 
163
159
  # clear widgets generated content
@@ -187,8 +183,8 @@ class Widget
187
183
  end
188
184
 
189
185
  output(*@_args, &@_block)
190
- before_to_s if self.methods.include?('before_to_s')
191
- content = @_content.to_s
186
+ before_to_s if self.respond_to?(:before_to_s)
187
+ out = @_content.to_s
192
188
 
193
189
  if @_profiler then
194
190
  Profiler__::stop_profile
@@ -196,7 +192,7 @@ class Widget
196
192
  Profiler__::print_profile(@_profiler)
197
193
  end
198
194
 
199
- return content
195
+ out
200
196
  end
201
197
 
202
198
 
@@ -209,7 +205,8 @@ class Widget
209
205
 
210
206
  # tries to run a class method if defined and return it
211
207
  def self.run_attr_method(name)
212
- return nil unless self.methods.include?(name)
208
+ return nil unless self.respond_to?(name.intern)
209
+
213
210
  self.send(name.intern)
214
211
  end
215
212
 
data/lib/cuca_cli.rb ADDED
@@ -0,0 +1,14 @@
1
+ # This file is -r required when runnung script/console to load
2
+ # support files automatically.
3
+ # Only for the CLI irb console
4
+
5
+ require 'cuca/urlmap'
6
+
7
+ puts "Cuca console: type: url [/some/path] to load support files of your app"
8
+ $app = Cuca::App.new
9
+
10
+ def url(some_path)
11
+ $app.load_support_files(Cuca::URLMap.new($cuca_path+'/app', some_path))
12
+ end
13
+
14
+ url '/'
data/tests/controller.rb CHANGED
@@ -8,15 +8,15 @@ require 'cuca/urlmap'
8
8
 
9
9
  class TestAController < Cuca::Controller
10
10
  def get
11
- content << 'GET'
11
+ @_content = 'GET'
12
12
  end
13
13
  def post
14
- content << 'POST'
14
+ @_content = 'POST'
15
15
  end
16
16
  end
17
17
  class TestBController < Cuca::Controller
18
18
  def run
19
- content << 'RUN'
19
+ @_content = 'RUN'
20
20
  end
21
21
  end
22
22
 
@@ -129,7 +129,19 @@ class ChainCController < ChainBController
129
129
  end
130
130
 
131
131
 
132
-
132
+ class StopFilterController < Cuca::Controller
133
+ before_filter 'stop_it'
134
+
135
+ def stop_it
136
+ stop :cancel_execution => true
137
+ end
138
+
139
+ def run
140
+ raise "Never got here"
141
+ end
142
+ end
143
+
144
+
133
145
 
134
146
  class ControllerTests < Test::Unit::TestCase
135
147
 
@@ -195,6 +207,10 @@ class ControllerTests < Test::Unit::TestCase
195
207
  c.run_before_filters
196
208
  assert_equal 'acb', c.out
197
209
  end
198
-
199
210
 
211
+ def test_stop_in_filter
212
+ c = StopFilterController.new
213
+ c.run_before_filters
214
+ c._do('run')
215
+ end
200
216
  end
@@ -11,7 +11,7 @@ class TestMabAWidget < Cuca::Widget
11
11
  include Cuca::Generator::Markaby
12
12
 
13
13
  def output(param1='one', param2='two')
14
- mab { b { param1}; b {param2}}
14
+ mab { b { param1 }; b { param2 }}
15
15
  end
16
16
  end
17
17
 
data/tests/widget.rb CHANGED
@@ -140,7 +140,8 @@ class WidgetTest < Test::Unit::TestCase
140
140
 
141
141
  def test_attr_method
142
142
  assert_equal 'stuff', TestDWidget.run_attr_method('something')
143
-
143
+ assert_equal 'stuff', TestDWidget.something
144
+
144
145
  a = TestEWidget.run_attr_method('something')
145
146
  assert a.instance_of?(Array)
146
147
  assert_equal 3, a.length
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cuca
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.06"
4
+ hash: 5
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 7
9
+ version: "0.07"
5
10
  platform: ruby
6
11
  authors:
7
12
  - Martin Boese
@@ -9,30 +14,31 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2009-03-04 00:00:00 +01:00
17
+ date: 2011-05-19 00:00:00 +01:00
13
18
  default_executable:
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
21
  name: markaby
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
20
25
  requirements:
21
26
  - - ">="
22
27
  - !ruby/object:Gem::Version
28
+ hash: 1
29
+ segments:
30
+ - 0
31
+ - 5
23
32
  version: "0.5"
24
- version:
25
- - !ruby/object:Gem::Dependency
26
- name: fcgi
27
33
  type: :runtime
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: 0.8.7
34
- version:
35
- description: Cuca is a light web development framework that supports CGI and FastCGI. It has a widget-bases approach to reuse functionality and does not implement an MVC architecture. Content can be generated directly by the controller with the help of external widgets that can generate code using markaby, eruby or any other user implemented 'generator'. It supports pretty URL's, layouts, sessions and the rendering of 'partials'.
34
+ version_requirements: *id001
35
+ description: |
36
+ Cuca is a light web development framework that supports CGI and FastCGI. It has
37
+ a widget-bases approach to reuse functionality and does not implement an MVC architecture. Content
38
+ can be generated directly by the controller with the help of external widgets that can generate code using
39
+ markaby, eruby or any other user implemented 'generator'. It supports pretty URL's, layouts,
40
+ sessions and the rendering of 'partials'.
41
+
36
42
  email: boesemar@gmx.de
37
43
  executables:
38
44
  - cuca
@@ -43,132 +49,126 @@ extra_rdoc_files:
43
49
  - README
44
50
  files:
45
51
  - bin/cuca
46
- - lib/cuca
47
- - lib/cuca/mimetypes.rb
48
- - lib/cuca/sessionpage.rb
49
- - lib/cuca/urlmap.rb
52
+ - lib/cuca.rb
53
+ - lib/cuca_console.rb
54
+ - lib/cuca_cli.rb
50
55
  - lib/cuca/layout.rb
51
- - lib/cuca/widget.rb
52
- - lib/cuca/cgi_fix.rb
56
+ - lib/cuca/cgi_emu.rb
57
+ - lib/cuca/app.rb
53
58
  - lib/cuca/const.rb
54
- - lib/cuca/sessionflash.rb
55
- - lib/cuca/controller.rb
59
+ - lib/cuca/generator/view.rb
60
+ - lib/cuca/generator/markaby.rb
61
+ - lib/cuca/app_cgi.rb
62
+ - lib/cuca/widget.rb
56
63
  - lib/cuca/session.rb
57
- - lib/cuca/app.rb
58
- - lib/cuca/config.rb
59
- - lib/cuca/test
64
+ - lib/cuca/session.rb-cgi
65
+ - lib/cuca/urlmap.rb
66
+ - lib/cuca/sessionpage.rb
67
+ - lib/cuca/controller.rb
60
68
  - lib/cuca/test/helpers.rb
61
- - lib/cuca/stdlib
62
69
  - lib/cuca/stdlib/slink.rb
70
+ - lib/cuca/stdlib/old_arform.rb
71
+ - lib/cuca/stdlib/formelements.rb
72
+ - lib/cuca/stdlib/arform.rb
63
73
  - lib/cuca/stdlib/link.rb
64
- - lib/cuca/stdlib/form.rb
65
74
  - lib/cuca/stdlib/list.rb
75
+ - lib/cuca/stdlib/formelements.rbs
76
+ - lib/cuca/stdlib/form.rb
66
77
  - lib/cuca/stdlib/arview.rb
67
- - lib/cuca/stdlib/arform.rb
68
- - lib/cuca/stdlib/old_arform.rb
69
- - lib/cuca/stdlib/listwidget
70
- - lib/cuca/stdlib/listwidget/list.rb
78
+ - lib/cuca/stdlib/formerrors.rb
71
79
  - lib/cuca/stdlib/listwidget/dblist.rb
80
+ - lib/cuca/stdlib/listwidget/list.rb
72
81
  - lib/cuca/stdlib/listwidget/querydef.rb
73
82
  - lib/cuca/stdlib/listwidget/staticdatalist.rb
74
- - lib/cuca/stdlib/formerrors.rb
75
- - lib/cuca/stdlib/formelements.rb
76
- - lib/cuca/generator
77
- - lib/cuca/generator/markaby.rb
78
- - lib/cuca/generator/view.rb
79
- - lib/cuca/cgi_emu.rb
80
- - lib/cuca_console.rb
81
- - lib/cuca.rb
82
- - tests/mimetypes.rb
83
- - tests/urlmap.rb
83
+ - lib/cuca/mimetypes.rb
84
+ - lib/cuca/generator_context.rb
85
+ - lib/cuca/cgi_fix.rb
86
+ - lib/cuca/sessionflash.rb
87
+ - lib/cuca/config.rb
84
88
  - tests/generator_markaby.rb
85
- - tests/all.rb
86
- - tests/widget.rb
87
89
  - tests/generator_view.rb
88
- - tests/controller.rb
89
90
  - tests/app.rb
90
- - tests/test_app
91
- - tests/test_app/conf
91
+ - tests/widget.rb
92
+ - tests/all.rb
93
+ - tests/test_app/app/user/list.rb
94
+ - tests/test_app/app/user/__username/index.rb
95
+ - tests/test_app/app/_views/test_template.rhtml
96
+ - tests/test_app/app/agent/index.rb
97
+ - tests/test_app/app/agent/list.rb
92
98
  - tests/test_app/conf/environment.rb
93
99
  - tests/test_app/conf/config.rb
94
- - tests/test_app/log
95
100
  - tests/test_app/log/messages
96
101
  - tests/test_app/README
97
- - tests/test_app/app
98
- - tests/test_app/app/agent
99
- - tests/test_app/app/agent/index.rb
100
- - tests/test_app/app/agent/list.rb
101
- - tests/test_app/app/_views
102
- - tests/test_app/app/_views/test_template.rhtml
103
- - tests/test_app/app/user
104
- - tests/test_app/app/user/__username
105
- - tests/test_app/app/user/__username/index.rb
106
- - tests/test_app/app/user/list.rb
107
- - application_skeleton/tests
108
- - application_skeleton/tests/widgets
102
+ - tests/urlmap.rb
103
+ - tests/controller.rb
104
+ - tests/mimetypes.rb
109
105
  - application_skeleton/tests/widgets/link.rb
110
- - application_skeleton/conf
111
- - application_skeleton/conf/environment.rb
112
- - application_skeleton/conf/config.rb
113
- - application_skeleton/public
114
- - application_skeleton/public/img
115
- - application_skeleton/public/img/cuca-seagull.png
116
- - application_skeleton/public/dispatch.cgi
117
- - application_skeleton/public/dispatch.fcgi
118
- - application_skeleton/public/500.html
119
- - application_skeleton/public/css
120
- - application_skeleton/public/css/style.css
121
- - application_skeleton/public/404.html
122
- - application_skeleton/scripts
123
- - application_skeleton/scripts/server-lighttpd-fcgi.rb
106
+ - application_skeleton/scripts/server-lighttpd.rb
124
107
  - application_skeleton/scripts/server-webrick.rb
108
+ - application_skeleton/scripts/server-webrick-cgihandler.rb
125
109
  - application_skeleton/scripts/console.rb
126
- - application_skeleton/scripts/server-lighttpd.rb
110
+ - application_skeleton/scripts/server-rack-thin.rb
127
111
  - application_skeleton/scripts/test.rb
128
- - application_skeleton/lib
129
- - application_skeleton/log
130
- - application_skeleton/log/access.log
131
- - application_skeleton/log/error.log
132
- - application_skeleton/log/messages
133
- - application_skeleton/README
134
- - application_skeleton/app
135
- - application_skeleton/app/_widgets
136
- - application_skeleton/app/_widgets/sourcecode.rb
137
- - application_skeleton/app/_widgets/test.rb
112
+ - application_skeleton/scripts/server-lighttpd-fcgi.rb
113
+ - application_skeleton/scripts/rack-test.rb
114
+ - application_skeleton/scripts/server-rack-webrick.rb
115
+ - application_skeleton/public/dispatch.fcgi
116
+ - application_skeleton/public/dispatch.cgi
117
+ - application_skeleton/public/dispatch.fcgi-old
118
+ - application_skeleton/public/dispatch-fwdev.cgi
119
+ - application_skeleton/public/css/style.css
120
+ - application_skeleton/public/dispatch.cgi-old
121
+ - application_skeleton/public/img/cuca-seagull.png
122
+ - application_skeleton/public/500.html
123
+ - application_skeleton/public/404.html
138
124
  - application_skeleton/app/index.rb
139
- - application_skeleton/app/_views
140
- - application_skeleton/app/_layouts
141
- - application_skeleton/app/_layouts/simple.rb
142
125
  - application_skeleton/app/demo.rb
143
- - application_skeleton/app/_controllers
144
126
  - application_skeleton/app/_controllers/application.rb
127
+ - application_skeleton/app/_widgets/test.rb
128
+ - application_skeleton/app/_widgets/sourcecode.rb
129
+ - application_skeleton/app/_layouts/simple.rb
130
+ - application_skeleton/conf/environment.rb
131
+ - application_skeleton/conf/config.rb
132
+ - application_skeleton/log/error.log
133
+ - application_skeleton/log/messages
134
+ - application_skeleton/log/access.log
135
+ - application_skeleton/README
145
136
  - CHANGELOG
146
137
  - README
147
138
  has_rdoc: true
148
139
  homepage: http://cuca.rubyforge.org/
149
- post_install_message:
150
- rdoc_options: []
140
+ licenses: []
151
141
 
142
+ post_install_message:
143
+ rdoc_options:
144
+ - --main
145
+ - README
152
146
  require_paths:
153
147
  - lib
154
148
  required_ruby_version: !ruby/object:Gem::Requirement
149
+ none: false
155
150
  requirements:
156
151
  - - ">="
157
152
  - !ruby/object:Gem::Version
153
+ hash: 3
154
+ segments:
155
+ - 0
158
156
  version: "0"
159
- version:
160
157
  required_rubygems_version: !ruby/object:Gem::Requirement
158
+ none: false
161
159
  requirements:
162
160
  - - ">="
163
161
  - !ruby/object:Gem::Version
162
+ hash: 3
163
+ segments:
164
+ - 0
164
165
  version: "0"
165
- version:
166
166
  requirements: []
167
167
 
168
168
  rubyforge_project: cuca
169
- rubygems_version: 1.2.0
169
+ rubygems_version: 1.3.7
170
170
  signing_key:
171
- specification_version: 2
171
+ specification_version: 3
172
172
  summary: A widget-based web framework
173
173
  test_files: []
174
174