thorero-helpers 0.5.0.11 → 0.9.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,54 @@
1
+ module Ordinalize
2
+ # Ordinalize turns a number into an ordinal string used to denote the
3
+ # position in an ordered sequence such as 1st, 2nd, 3rd, 4th.
4
+ #
5
+ # Examples
6
+ # 1.ordinalize # => "1st"
7
+ # 2.ordinalize # => "2nd"
8
+ # 1002.ordinalize # => "1002nd"
9
+ # 1003.ordinalize # => "1003rd"
10
+ def ordinalize
11
+ if (11..13).include?(self % 100)
12
+ "#{self}th"
13
+ else
14
+ case self % 10
15
+ when 1; "#{self}st"
16
+ when 2; "#{self}nd"
17
+ when 3; "#{self}rd"
18
+ else "#{self}th"
19
+ end
20
+ end
21
+ end
22
+ end
23
+
24
+ Integer.send :include, Ordinalize
25
+
26
+ # Time.now.to_ordinalized_s :long
27
+ # => "February 28th, 2006 21:10"
28
+ module OrdinalizedFormatting
29
+
30
+ def self.extended(obj)
31
+ include Merb::Helpers::DateAndTime
32
+ end
33
+
34
+ def to_ordinalized_s(format = :default)
35
+ format = Merb::Helpers::DateAndTime.date_formats[format]
36
+ return self.to_s if format.nil?
37
+ strftime_ordinalized(format)
38
+ end
39
+
40
+ # Gives you a relative date in an attractive format
41
+ #
42
+ # ==== Parameters
43
+ # format<String>:: strftime string used to formatt a time/date object
44
+ # locale<String, Symbol>:: An optional value which can be used by localization plugins
45
+ #
46
+ # ==== Returns
47
+ # String:: Ordinalized time/date object
48
+ #
49
+ # ==== Examples
50
+ # 5.days.ago.strftime_ordinalized('%b %d, %Y') # =>
51
+ def strftime_ordinalized(fmt, format=nil)
52
+ strftime(fmt.gsub(/(^|[^-])%d/, '\1_%d_')).gsub(/_(\d+)_/) { |s| s.to_i.ordinalize }
53
+ end
54
+ end
@@ -0,0 +1,61 @@
1
+ module Merb
2
+ module Helpers
3
+ module Tag
4
+ # Creates a generic HTML tag. You can invoke it a variety of ways.
5
+ #
6
+ # tag :div
7
+ # # <div></div>
8
+ #
9
+ # tag :div, 'content'
10
+ # # <div>content</div>
11
+ #
12
+ # tag :div, :class => 'class'
13
+ # # <div class="class"></div>
14
+ #
15
+ # tag :div, 'content', :class => 'class'
16
+ # # <div class="class">content</div>
17
+ #
18
+ # tag :div do
19
+ # 'content'
20
+ # end
21
+ # # <div>content</div>
22
+ #
23
+ # tag :div, :class => 'class' do
24
+ # 'content'
25
+ # end
26
+ # # <div class="class">content</div>
27
+ #
28
+ def tag(name, contents = nil, attrs = {}, &block)
29
+ attrs, contents = contents, nil if contents.is_a?(Hash)
30
+ contents = capture(&block) if block_given?
31
+ open_tag(name, attrs) + contents.to_s + close_tag(name)
32
+ end
33
+
34
+ # Creates the opening tag with attributes for the provided +name+
35
+ # attrs is a hash where all members will be mapped to key="value"
36
+ #
37
+ # Note: This tag will need to be closed
38
+ def open_tag(name, attrs = nil)
39
+ "<#{name}#{' ' + attrs.to_html_attributes if attrs && !attrs.empty?}>"
40
+ end
41
+
42
+ # Creates a closing tag
43
+ def close_tag(name)
44
+ "</#{name}>"
45
+ end
46
+
47
+ # Creates a self closing tag. Like <br/> or <img src="..."/>
48
+ #
49
+ # +name+ : the name of the tag to create
50
+ # +attrs+ : a hash where all members will be mapped to key="value"
51
+ def self_closing_tag(name, attrs = nil)
52
+ "<#{name}#{' ' + attrs.to_html_attributes if attrs && !attrs.empty?}/>"
53
+ end
54
+
55
+ end
56
+ end
57
+ end
58
+
59
+ class Merb::Controller
60
+ include Merb::Helpers::Tag
61
+ end
@@ -0,0 +1,59 @@
1
+ # Provides a a simple way of calling time units and to see the elapsed time between 2 moments
2
+ # ==== Examples
3
+ # 142.minutes => returns a value in seconds
4
+ # 7.days => returns a value in seconds
5
+ # 1.week => returns a value in seconds
6
+ # 2.weeks.ago => returns a date
7
+ # 1.year.since(time) => returns a date
8
+ # 5.months.since(2.weeks.from_now) => returns a date
9
+ module TimeDSL
10
+
11
+ def second
12
+ self * 1
13
+ end
14
+ alias_method :seconds, :second
15
+
16
+ def minute
17
+ self * 60
18
+ end
19
+ alias_method :minutes, :minute
20
+
21
+ def hour
22
+ self * 3600
23
+ end
24
+ alias_method :hours, :hour
25
+
26
+ def day
27
+ self * 86400
28
+ end
29
+ alias_method :days, :day
30
+
31
+ def week
32
+ self * 604800
33
+ end
34
+ alias_method :weeks, :week
35
+
36
+ def month
37
+ self * 2592000
38
+ end
39
+ alias_method :months, :month
40
+
41
+ def year
42
+ self * 31471200
43
+ end
44
+ alias_method :years, :year
45
+
46
+ # Reads best without arguments: 10.minutes.ago
47
+ def ago(time = ::Time.now)
48
+ time - self
49
+ end
50
+ alias :until :ago
51
+
52
+ # Reads best with argument: 10.minutes.since(time)
53
+ def since(time = ::Time.now)
54
+ time + self
55
+ end
56
+ alias :from_now :since
57
+ end
58
+
59
+ Numeric.send :include, TimeDSL
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thorero-helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0.11
4
+ version: 0.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yehuda Katz
@@ -22,7 +22,7 @@ dependencies:
22
22
  - !ruby/object:Gem::Version
23
23
  version: 0.9.4
24
24
  version:
25
- description: Merb plugin that provides support for Laszlo.
25
+ description: Helper support for merb (similar to the Rails form helpers)
26
26
  email: ykatz@engineyard.com
27
27
  executables: []
28
28
 
@@ -31,15 +31,20 @@ extensions: []
31
31
  extra_rdoc_files:
32
32
  - README
33
33
  - LICENSE
34
+ - TODO
34
35
  files:
35
36
  - LICENSE
36
37
  - README
37
38
  - Rakefile
38
- - lib/merb-laszlo
39
- - lib/merb-laszlo/controllers.rb
40
- - lib/merb-laszlo/helpers.rb
41
- - lib/merb-laszlo/merbtasks.rb
42
- - lib/merb-laszlo.rb
39
+ - TODO
40
+ - lib/merb_helpers
41
+ - lib/merb_helpers/core_ext.rb
42
+ - lib/merb_helpers/date_time_helpers.rb
43
+ - lib/merb_helpers/form_helpers.rb
44
+ - lib/merb_helpers/ordinalize.rb
45
+ - lib/merb_helpers/tag_helpers.rb
46
+ - lib/merb_helpers/time_dsl.rb
47
+ - lib/merb_helpers.rb
43
48
  has_rdoc: true
44
49
  homepage: http://merbivore.com
45
50
  post_install_message:
@@ -65,6 +70,6 @@ rubyforge_project: thorero
65
70
  rubygems_version: 1.2.0
66
71
  signing_key:
67
72
  specification_version: 2
68
- summary: Merb plugin that provides support for Laszlo.
73
+ summary: Helper support for merb (similar to the Rails form helpers)
69
74
  test_files: []
70
75
 
@@ -1,38 +0,0 @@
1
- require "digest/md5"
2
- require "fileutils"
3
- require "curb"
4
- require "zip/zip"
5
- srand(Time.now.to_i)
6
-
7
- class Laszlo
8
- def self.file_name
9
- Digest::MD5.hexdigest(rand(Time.now.to_i).to_s)
10
- end
11
-
12
- def self.app_name
13
- File.basename(File.expand_path(Merb.root))
14
- end
15
-
16
- cattr_accessor :url
17
- end
18
-
19
- require "haml"
20
-
21
- module Haml
22
- module Filters
23
- module Cdata
24
- include Haml::Filters::Base
25
-
26
- def render(text)
27
- "<![CDATA[#{("\n" + text).rstrip.gsub("\n", "\n ")}\n]]>"
28
- end
29
- end
30
- end
31
- end
32
-
33
- Merb::Config[:haml] ||= {}
34
- Merb::Config[:haml][:filters] ||= {}
35
- Merb::Config[:haml][:filters].merge!("cdata" => Haml::Filters::Cdata)
36
-
37
- require "merb-laszlo/controllers"
38
- require "merb-laszlo/helpers"
@@ -1,53 +0,0 @@
1
- require "pathname"
2
- module Merb
3
- class Controller
4
-
5
- def laszlo(str)
6
- @lz_resources ||= []
7
-
8
- root, template_location = self.class._template_roots.last
9
- resource_dir = root / send(template_location, "resources")[0...-1]
10
- Merb.logger.info! "Resource dir: #{resource_dir}"
11
-
12
- zip_filename = "#{Laszlo.file_name}.zip"
13
- FileUtils.mkdir_p(Merb.root / "tmp")
14
- Zip::ZipFile.open(Merb.root / "tmp" / zip_filename, Zip::ZipFile::CREATE) do |zipfile|
15
- zipfile.get_output_stream("#{action_name}.lzx") do |f|
16
- f.puts str
17
- end
18
- @lz_resources.each do |resource|
19
- filepath = resource.split("/")
20
- dir = filepath[1...-1].join("/").gsub(/^#{Merb.root}/, "")
21
- filename = filepath[-1]
22
- zipfile.mkdir(dir) unless zipfile.find_entry(dir) || dir.empty?
23
- Merb.logger.info! "Looking for #{resource_dir / resource}"
24
- if File.file?(resource_dir / resource)
25
- zipfile.add(resource, resource_dir / resource)
26
- elsif File.file?(root / resource)
27
- zipfile.add(resource, root / resource)
28
- end
29
- end
30
- end
31
- c = Curl::Easy.new
32
-
33
- c.url = "#{Laszlo.url}/file_upload.jsp"
34
- c.multipart_form_post = true
35
-
36
- file = Curl::PostField.file("myFile", Merb.root / "tmp" / zip_filename, zip_filename)
37
- file.content_type = "application/zip"
38
-
39
- c.http_post(
40
- file,
41
- Curl::PostField.content("uid", "#{Laszlo.app_name}__#{controller_name}"))
42
-
43
- File.delete(Merb.root / "tmp" / zip_filename)
44
-
45
- if c.response_code == 200
46
- redirect("#{Laszlo.url}/my-apps/#{Laszlo.app_name}__#{controller_name}/#{action_name}.lzx")
47
- else
48
- raise NotAcceptable
49
- end
50
- end
51
-
52
- end
53
- end
@@ -1,45 +0,0 @@
1
- module Merb
2
- module GlobalHelpers
3
-
4
- def lz(name, *args, &blk)
5
- send("lz_#{name}", *args, &blk)
6
- end
7
-
8
- def lz_reload_button
9
- contents = "Reload" +
10
- tag(:handler, %{LzBrowser.loadJS("window.location = \\\"#{request.full_uri}\\\"")}, :name => "onclick") +
11
- tag(:handler, %{this.bringToFront()}, :name => "oninit")
12
-
13
- tag(:button, contents, :valign => "bottom", :align => "right")
14
- end
15
-
16
- def lz_class(name, extends = nil, opts = {}, &blk)
17
- opts.merge!(:name => name)
18
- opts.merge!(:extends => extends) if extends
19
- tag(:class, nil, opts, &blk)
20
- end
21
-
22
- def lz_text(text, opts = {})
23
- self_closing_tag(:text, {:text => text}.merge(opts))
24
- end
25
-
26
- def lz_window(width, height, opts = {}, &blk)
27
- opts = {:resizable => true, :width => width, :height => height}.merge!(opts)
28
- tag(:window, nil, opts, &blk)
29
- end
30
-
31
- def lz_resource(name, src, opts = {})
32
- @lz_resources ||= []
33
- @lz_resources << src
34
- opts.merge!(:name => name, :src => src)
35
- self_closing_tag(:resource, opts)
36
- end
37
-
38
- def lz_on(name, options = {}, *args, &blk)
39
- options.merge!(:name => "on#{name}")
40
- options.merge!(:args => args.map {|x| x.to_s}.join(", ")) unless args.empty?
41
- tag(:handler, capture(&blk), options)
42
- end
43
-
44
- end
45
- end
@@ -1,6 +0,0 @@
1
- namespace :merb-laszlo do
2
- desc "Do something for merb-laszlo"
3
- task :default do
4
- puts "merb-laszlo doesn't do anything"
5
- end
6
- end