kelredd-useful 0.1.10 → 0.1.11

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.
@@ -1,11 +1,5 @@
1
1
  Capistrano::Configuration.instance.load do
2
2
  namespace :cache do
3
3
 
4
- desc "Update code, run 'rake gems:install'"
5
- task :install, :roles => :app do
6
- deploy.update_code
7
- run "cd #{current_release}; sudo #{fetch(:rake, "rake")} #{"RAILS_ENV=#{rails_env}" if defined?(rails_env)} gems:install"
8
- end
9
-
10
4
  end
11
5
  end
@@ -1,10 +1,10 @@
1
1
  Capistrano::Configuration.instance.load do
2
- namespace :gems do
2
+ namespace :gemsconfig do
3
3
 
4
- desc "Update code, run 'rake gems:install'"
4
+ desc "Update code, run 'rake gemsconfig:install'"
5
5
  task :install, :roles => fetch(:install_roles, :app) do
6
6
  deploy.update_code
7
- run_with_password("sudo #{fetch(:rake, "rake")} -f #{current_release}/Rakefile #{"RAILS_ENV=#{rails_env}" if rails_env} #{fetch(:gems, "gems")}:install", {
7
+ run_with_password("sudo #{fetch(:rake, "rake")} -f #{current_release}/Rakefile #{"RAILS_ENV=#{rails_env}" if rails_env} #{fetch(:gemsconfig, "gemsconfig")}:install", {
8
8
  :prompt => "Enter sudo pw: ",
9
9
  :pty => false
10
10
  })
@@ -0,0 +1,131 @@
1
+ require 'sinatra/base'
2
+ require File.join(File.dirname(__FILE__), 'helpers.rb')
3
+ require File.join(File.dirname(__FILE__), 'tags.rb')
4
+
5
+ module Useful
6
+ module SinatraHelpers
7
+ module Erb
8
+ module Forms
9
+
10
+ include Useful::SinatraHelpers::Erb::Helpers
11
+
12
+ def form_tag(url, options={}, &block)
13
+ options[:method] = 'post' unless ['get','post','put','delete'].include?(options[:method])
14
+ options.update :action => url
15
+ if multipart = options.delete(:multipart)
16
+ options[:enctype] = sinatra_erb_helper_multipart_option
17
+ end
18
+ if block_given?
19
+ @_out_buf << tag(:form, options) { sinatra_erb_helper_capture(&block) }
20
+ else
21
+ tag(:form, options)
22
+ end
23
+ end
24
+
25
+ def field_set_tag(legend=nil, options={}, &block)
26
+ legend_html = legend.nil? ? '' : tag(:legend) { legend.to_s }
27
+ if block_given?
28
+ @_out_buf << tag(:fieldset, options) { legend_html + sinatra_erb_helper_capture(&block) }
29
+ else
30
+ tag(:fieldset, options) { legend_html }
31
+ end
32
+ end
33
+
34
+ def label_tag(name, value=nil, options={})
35
+ value ||= name.to_s.capitalize
36
+ options.update :for => name.to_s
37
+ tag(:label, options) { value }
38
+ end
39
+
40
+ def hidden_field_tag(name, value=nil, options={})
41
+ input_tag('hidden', name, value, options)
42
+ end
43
+
44
+ def password_field_tag(name="password", value=nil, options={})
45
+ options[:disabled] = sinatra_erb_helper_disabled_option if options[:disabled]
46
+ input_tag('password', name, value, options)
47
+ end
48
+
49
+ def file_field_tag(name, options={})
50
+ options[:disabled] = sinatra_erb_helper_disabled_option if options[:disabled]
51
+ input_tag('file', name, nil, options)
52
+ end
53
+
54
+ def check_box_tag(name, label=nil, value='1', checked=false, options={})
55
+ tag_name = options.delete(:tag) || :div
56
+ if options.has_key?(:class)
57
+ options[:class] += ' checkbox'
58
+ else
59
+ options[:class] = 'checkbox'
60
+ end
61
+ options[:id] ||= sinatra_erb_helper_safe_id(rand(1000).to_s)
62
+ options[:disabled] = sinatra_erb_helper_disabled_option if options[:disabled]
63
+ options[:checked] = sinatra_erb_helper_checked_option if checked
64
+ input_str = input_tag('checkbox', name, value, options)
65
+ if label.nil?
66
+ input_str
67
+ else
68
+ tag(tag_name, :class => 'checkbox') { input_str + label_tag(options[:id], label) }
69
+ end
70
+ end
71
+
72
+ def radio_button_tag(name, value, label=nil, checked=false, options={})
73
+ tag_name = options.delete(:tag) || :span
74
+ if options.has_key?(:class)
75
+ options[:class] += ' radiobutton'
76
+ else
77
+ options[:class] = 'radiobutton'
78
+ end
79
+ label ||= value.to_s.capitalize
80
+ options[:id] ||= sinatra_erb_helper_safe_id(rand(1000).to_s)
81
+ options[:disabled] = sinatra_erb_helper_disabled_option if options[:disabled]
82
+ options[:checked] = sinatra_erb_helper_checked_option if checked
83
+ input_str = input_tag('radio', name, value, options)
84
+ if label.nil?
85
+ input_str
86
+ else
87
+ label_tag(options[:id], input_str + tag(tag_name) { label }, :class => options.delete(:class))
88
+ end
89
+ end
90
+
91
+ def select_tag(name, options={}, &block)
92
+ options[:disabled] = sinatra_erb_helper_disabled_option if options[:disabled]
93
+ html_name = (options[:multiple] == true && !name.to_s[(name.to_s.length-2)..-1] == "[]") ? "#{name}[]" : name
94
+ options[:multiple] = sinatra_erb_helper_multiple_option if options[:multiple] == true
95
+ options[:tag] = 'select'
96
+ if block_given?
97
+ @_out_buf << input_tag(:select, html_name, nil, options) { sinatra_erb_helper_capture(&block) }
98
+ else
99
+ input_tag(:select, html_name, nil, options)
100
+ end
101
+ end
102
+
103
+ def text_area_tag(name, content=nil, options={})
104
+ options[:disabled] = sinatra_erb_helper_disabled_option if options[:disabled]
105
+ options[:tag] = 'textarea'
106
+ input_tag(nil, name, nil, options) { content || '' }
107
+ end
108
+
109
+ def text_field_tag(name, value=nil, options={})
110
+ options[:disabled] = sinatra_erb_helper_disabled_option if options[:disabled]
111
+ input_tag('text', name, value, options)
112
+ end
113
+
114
+ def submit_tag(value="Save", options={})
115
+ options[:disabled] = sinatra_erb_helper_disabled_option if options[:disabled]
116
+ input_tag('submit', 'commit', value, options)
117
+ end
118
+
119
+ def image_submit_tag(source, options={})
120
+ options[:disabled] = sinatra_erb_helper_disabled_option if options[:disabled]
121
+ options[:src] = source
122
+ options[:alt] ||= 'Save'
123
+ input_tag('image', nil, nil, options)
124
+ end
125
+
126
+ end
127
+ end
128
+ end
129
+ end
130
+
131
+ Sinatra::Application.helpers Useful::SinatraHelpers::Erb::Forms
@@ -0,0 +1,45 @@
1
+ module Useful
2
+ module SinatraHelpers
3
+ module Erb
4
+ module Helpers
5
+
6
+ def sinatra_erb_helper_safe_id(id)
7
+ id.gsub(/\W/,'')
8
+ end
9
+
10
+ def sinatra_erb_helper_capture(*args, &block)
11
+ sinatra_erb_helper_with_output_buffer { block.call(*args) }
12
+ end
13
+
14
+ def sinatra_erb_helper_with_output_buffer(buf = '') #:nodoc:
15
+ @_out_buf, old_buffer = buf, @_out_buf
16
+ yield
17
+ @_out_buf
18
+ ensure
19
+ @_out_buf = old_buffer
20
+ end
21
+
22
+ def sinatra_erb_helper_hash_to_html_attrs(a_hash)
23
+ a_hash.collect{|key, val| "#{key}=\"#{val}\""}.join(' ')
24
+ end
25
+
26
+ def sinatra_erb_helper_disabled_option
27
+ 'disabled'
28
+ end
29
+
30
+ def sinatra_erb_helper_checked_option
31
+ 'checked'
32
+ end
33
+
34
+ def sinatra_erb_helper_multiple_option
35
+ 'multiple'
36
+ end
37
+
38
+ def sinatra_erb_helper_multipart_option
39
+ 'multipart/form-data'
40
+ end
41
+
42
+ end
43
+ end
44
+ end
45
+ end
@@ -1,9 +1,9 @@
1
1
  require 'sinatra/base'
2
- require File.join(File.dirname(__FILE__), 'globals.rb')
2
+ require File.join(File.dirname(__FILE__), 'tags.rb')
3
3
 
4
4
  module Sinatra
5
5
  module SinatraHelpers
6
- module Tags
6
+ module Erb
7
7
  module Links
8
8
 
9
9
  # helper to emulate action view's 'link_to'
@@ -63,5 +63,5 @@ module Sinatra
63
63
  end
64
64
  end
65
65
 
66
- Sinatra::Application.helpers Sinatra::SinatraHelpers::Tags::Links
66
+ Sinatra::Application.helpers Sinatra::SinatraHelpers::Erb::Links
67
67
  end
@@ -3,17 +3,17 @@ require File.join(File.dirname(__FILE__), 'helpers.rb')
3
3
 
4
4
  module Useful
5
5
  module SinatraHelpers
6
- module Tags
7
- module Globals
6
+ module Erb
7
+ module Tags
8
8
 
9
- include Useful::SinatraHelpers::Tags::Helpers
9
+ include Useful::SinatraHelpers::Erb::Helpers
10
10
 
11
11
  def input_tag(type, name, value, options={}, &block)
12
12
  options[:tag] ||= :input
13
13
  options[:type] = type unless type.nil?
14
14
  unless name.nil?
15
15
  options[:name] = name
16
- options[:id] ||= sinatra_tag_helper_safe_id(name)
16
+ options[:id] ||= sinatra_erb_helper_safe_id(name)
17
17
  end
18
18
  options[:value] = value unless value.nil?
19
19
  tag(options.delete(:tag), options, &block)
@@ -32,8 +32,8 @@ module Useful
32
32
  # emulator for 'tag'
33
33
  # EX : tag :h1, "shizam", :title => "shizam"
34
34
  # => <h1 title="shizam">shizam</h1>
35
- def tag(name,options={})
36
- "<#{name.to_s} #{sinatra_tag_helper_hash_to_html_attrs(options)} #{block_given? ? ">#{yield}</#{name}" : "/"}>"
35
+ def tag(name, options={})
36
+ "<#{name.to_s} #{sinatra_erb_helper_hash_to_html_attrs(options)} #{block_given? ? ">#{yield}</#{name}" : "/"}>"
37
37
  end
38
38
 
39
39
  end
@@ -41,5 +41,5 @@ module Useful
41
41
  end
42
42
  end
43
43
 
44
- Sinatra::Application.helpers Useful::SinatraHelpers::Tags::Globals
44
+ Sinatra::Application.helpers Useful::SinatraHelpers::Erb::Tags
45
45
 
@@ -3,7 +3,7 @@ module Useful
3
3
 
4
4
  MAJOR = 0
5
5
  MINOR = 1
6
- TINY = 10
6
+ TINY = 11
7
7
 
8
8
  def self.to_s # :nodoc:
9
9
  [MAJOR, MINOR, TINY].join('.')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kelredd-useful
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kelredd
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-24 00:00:00 -07:00
12
+ date: 2009-06-25 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -30,7 +30,7 @@ files:
30
30
  - lib/useful/active_record_helpers.rb
31
31
  - lib/useful/cap_tasks
32
32
  - lib/useful/cap_tasks/cache.rb
33
- - lib/useful/cap_tasks/gems.rb
33
+ - lib/useful/cap_tasks/gemsconfig.rb
34
34
  - lib/useful/cap_tasks/globals.rb
35
35
  - lib/useful/cap_tasks.rb
36
36
  - lib/useful/rails_extensions
@@ -61,14 +61,12 @@ files:
61
61
  - lib/useful/sinatra_helpers/environment_tests.rb
62
62
  - lib/useful/sinatra_helpers/erb
63
63
  - lib/useful/sinatra_helpers/erb/error_pages.rb
64
+ - lib/useful/sinatra_helpers/erb/forms.rb
65
+ - lib/useful/sinatra_helpers/erb/helpers.rb
66
+ - lib/useful/sinatra_helpers/erb/links.rb
64
67
  - lib/useful/sinatra_helpers/erb/partials.rb
68
+ - lib/useful/sinatra_helpers/erb/tags.rb
65
69
  - lib/useful/sinatra_helpers/erb.rb
66
- - lib/useful/sinatra_helpers/tags
67
- - lib/useful/sinatra_helpers/tags/forms.rb
68
- - lib/useful/sinatra_helpers/tags/globals.rb
69
- - lib/useful/sinatra_helpers/tags/helpers.rb
70
- - lib/useful/sinatra_helpers/tags/links.rb
71
- - lib/useful/sinatra_helpers/tags.rb
72
70
  - lib/useful/sinatra_helpers.rb
73
71
  - lib/useful/version.rb
74
72
  - lib/useful.rb
@@ -1,110 +0,0 @@
1
- require 'sinatra/base'
2
- require File.join(File.dirname(__FILE__), 'helpers.rb')
3
- require File.join(File.dirname(__FILE__), 'globals.rb')
4
-
5
- module Useful
6
- module SinatraHelpers
7
- module Tags
8
- module Forms
9
-
10
- include Useful::SinatraHelpers::Tags::Helpers
11
-
12
- def form_tag(url, options={}, &block)
13
- options.update :action => url
14
- tag(:form, options, &block)
15
- end
16
-
17
- def field_set_tag(legend=nil, options=nil, &block)
18
- content = "#{tag(:legend) { lengend.to_s } unless legend.nil?}#{sinatra_tag_helper_capture(&block)}"
19
- tag(:fieldset, options) { content }
20
- end
21
-
22
- def label_tag(name, value=nil, options={})
23
- value ||= name.to_s.capitalize
24
- options.update :for => name.to_s
25
- tag(:label, options) { value }
26
- end
27
-
28
- def hidden_field_tag(name, value=nil, options={})
29
- input_tag('hidden', name, value, options)
30
- end
31
-
32
- def password_field_tag(name="password", value=nil, options={})
33
- options[:disabled] = sinatra_tag_helper_disabled_option if options[:disabled]
34
- input_tag('password', name, value, options)
35
- end
36
-
37
- def file_field_tag(name, options={})
38
- options[:disabled] = sinatra_tag_helper_disabled_option if options[:disabled]
39
- input_tag('file', name, nil, options)
40
- end
41
-
42
- def check_box_tag(name, label=nil, value='1', checked=false, options={})
43
- options[:tag] ||= :div
44
- if options.has_key?(:class)
45
- options[:class] += ' checkbox'
46
- else
47
- options[:class] = 'checkbox'
48
- end
49
- options[:disabled] = sinatra_tag_helper_disabled_option if options[:disabled]
50
- options[:checked] = sinatra_tag_helper_checked_option if checked
51
- input_str = input_tag('checkbox', name, value, options)
52
- if label.nil?
53
- input_str
54
- else
55
- tag(options.delete(:tag), :class => 'checkbox') { input_str + label_tag(options[:id], label) }
56
- end
57
- end
58
-
59
- def radio_button_tag(name, value, label, checked=false, options={})
60
- options[:tag] ||= :span
61
- if options.has_key?(:class)
62
- options[:class] += ' radiobutton'
63
- else
64
- options[:class] = 'radiobutton'
65
- end
66
- options[:disabled] = sinatra_tag_helper_disabled_option if options[:disabled]
67
- options[:checked] = sinatra_tag_helper_checked_option if checked
68
- input_str = input_tag('radio', name, value, options)
69
- if label.nil?
70
- input_str
71
- else
72
- label_tag(name, input_str + tag(options.delete(:tag)) { label }, :class => options.delete(:class))
73
- end
74
- end
75
-
76
- def select_tag(name, option_tags=nil, options={})
77
- options[:disabled] = sinatra_tag_helper_disabled_option if options[:disabled]
78
- html_name = (options[:multiple] == true && !name.to_s[(name.to_s.length-2)..-1] == "[]") ? "#{name}[]" : name
79
- options[:multiple] = sinatra_tag_helper_multiple_option if options[:multiple] == true
80
- input_tag('select', name, nil, options) { option_tags || '' }
81
- end
82
-
83
- def text_area_tag(name, content=nil, options={})
84
- options[:disabled] = sinatra_tag_helper_disabled_option if options[:disabled]
85
- options[:tag] = 'textarea'
86
- input_tag(nil, name, nil, options) { content || '' }
87
- end
88
-
89
- def text_field_tag(name, value=nil, options={})
90
- options[:disabled] = sinatra_tag_helper_disabled_option if options[:disabled]
91
- input_tag('text', name, value, options)
92
- end
93
-
94
- def submit_tag(value="Save", options={})
95
- options[:disabled] = sinatra_tag_helper_disabled_option if options[:disabled]
96
- input_tag('submit', 'commit', value, options)
97
- end
98
-
99
- def image_submit_tag(source, options={})
100
- options[:disabled] = sinatra_tag_helper_disabled_option if options[:disabled]
101
- options[:src] = source
102
- input_tag('image', nil, nil, options)
103
- end
104
-
105
- end
106
- end
107
- end
108
- end
109
-
110
- Sinatra::Application.helpers Useful::SinatraHelpers::Tags::Forms
@@ -1,33 +0,0 @@
1
- module Useful
2
- module SinatraHelpers
3
- module Tags
4
- module Helpers
5
-
6
- def sinatra_tag_helper_safe_id(id)
7
- id.gsub(/\W/,'')
8
- end
9
-
10
- def sinatra_tag_helper_capture(*args, &block)
11
- block.call(*args)
12
- end
13
-
14
- def sinatra_tag_helper_disabled_option
15
- 'disabled'
16
- end
17
-
18
- def sinatra_tag_helper_checked_option
19
- 'checked'
20
- end
21
-
22
- def sinatra_tag_helper_multiple_option
23
- 'multiple'
24
- end
25
-
26
- def sinatra_tag_helper_hash_to_html_attrs(a_hash)
27
- a_hash.collect{|key, val| "#{key}=\"#{val}\""}.join(' ')
28
- end
29
-
30
- end
31
- end
32
- end
33
- end
@@ -1,3 +0,0 @@
1
- Dir[File.join(File.dirname(__FILE__), "tags" ,"*.rb")].each do |file|
2
- require file
3
- end