rango 0.2.1.pre → 0.2.1

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.
@@ -2,28 +2,24 @@
2
2
 
3
3
  require "dm-aggregates"
4
4
 
5
- module Rango
6
- module Pagination
7
- module DataMapper
8
- module Model
9
- # @since 0.0.2
10
- # @example Post.paginate(page, order: [:updated_at.desc])
11
- def paginate(pagenum = 1, options = Hash.new)
12
- pagenum = 1 if pagenum.nil?
13
- page = self.page(pagenum.to_i, options)
14
- Page.current = page
15
- offset = page.number(:db) * page.per_page
16
- self.all(options.merge!(offset: offset, limit: page.per_page))
17
- end
5
+ module DataMapper
6
+ module Model
7
+ # @since 0.0.2
8
+ # @example Post.paginate(page, order: [:updated_at.desc])
9
+ def paginate(pagenum = 1, options = Hash.new)
10
+ pagenum = 1 if pagenum.nil?
11
+ page = self.page(pagenum.to_i, options)
12
+ Page.current = page
13
+ offset = page.number(:db) * page.per_page
14
+ self.all(options.merge!(offset: offset, limit: page.per_page))
15
+ end
18
16
 
19
- # @since 0.0.2
20
- def page(current, options = Hash.new)
21
- per_page = defined?(PER_PAGE) ? PER_PAGE : 10
22
- # the count options are very important
23
- # Product.count vs. Product.count(online: true)
24
- Page.new(current: current, count: self.count(options), per_page: per_page)
25
- end
26
- end
17
+ # @since 0.0.2
18
+ def page(current, options = Hash.new)
19
+ per_page = defined?(PER_PAGE) ? PER_PAGE : 10
20
+ # the count options are very important
21
+ # Product.count vs. Product.count(online: true)
22
+ Page.new(current: current, count: self.count(options), per_page: per_page)
27
23
  end
28
24
  end
29
25
  end
@@ -53,8 +53,6 @@ module Rango
53
53
  self.run_action
54
54
  #self.response.finish # do we need this?
55
55
  [response.status, response.headers, [response.body]] # this way we got real body rather than response object
56
- rescue Redirection => redirection
57
- redirection.to_response
58
56
  rescue HttpError => exception
59
57
  self.rescue_http_error(exception)
60
58
  end
@@ -68,22 +66,12 @@ module Rango
68
66
  def_delegators :response, :status, :status=
69
67
  def_delegators :response, :headers, :headers=
70
68
 
71
- # absolute_uri "http://google.com" => "http://google.com"
72
- # absolute_uri "/products" => "http://localhost:4000/products"
73
- def absolute_uri(path)
74
- if path.match(/^https?:\/{2}/)
75
- path
76
- else
77
- (request.base_url.chomp("/") + path).chomp("/")
78
- end
79
- end
80
-
81
69
  # @since 0.0.2
82
70
  # @version 0.2.1
83
71
  # @return [String] Escaped URL (which is RFC recommendation)
84
72
  def redirect(location, status = 301)
85
73
  if (300..399).include?(status)
86
- exception = Redirection.new(absolute_uri(location))
74
+ exception = Redirection.new(location)
87
75
  exception.status = status
88
76
  raise exception
89
77
  else
@@ -19,23 +19,6 @@ module Rango
19
19
  def context
20
20
  super.merge!(message: self.message)
21
21
  end
22
-
23
- def redirect(uri, status = 301, options = Hash.new)
24
- status, options = 301, status if status.is_a?(Hash)
25
- if options.respond_to?(:inject)
26
- # redirect "/post", error: "Try again"
27
- # ?msg[error]="Try again"
28
- uri = options.inject(uri) do |uri, pair|
29
- type, message = pair
30
- uri + "?msg[#{type}]=#{message}"
31
- end
32
- else
33
- # redirect "/post", "Try again"
34
- # ?msg="Try again"
35
- uri.concat("?msg=#{options}")
36
- end
37
- super(uri, status)
38
- end
39
22
  end
40
23
  end
41
24
  else
@@ -46,5 +29,27 @@ module Rango
46
29
  def message
47
30
  @message ||= (request.GET[:msg] || Hash.new)
48
31
  end
32
+
33
+ # @since 0.0.2
34
+ def redirect(url, options = Hash.new)
35
+ url = [self.request.base_url.chomp("/"), url].join("/").chomp("/") unless url.match(/^http/)
36
+
37
+ if options.respond_to?(:inject)
38
+ # redirect "/post", error: "Try again"
39
+ # ?msg[error]="Try again"
40
+ url = options.inject(url) do |url, pair|
41
+ type, message = pair
42
+ url + "?msg[#{type}]=#{message}"
43
+ end
44
+ else
45
+ # redirect "/post", "Try again"
46
+ # ?msg="Try again"
47
+ url.concat("?msg=#{options}")
48
+ end
49
+
50
+ self.status = 302
51
+ self.headers["Location"] = URI.escape(url)
52
+ return String.new
53
+ end
49
54
  end
50
55
  end
@@ -4,8 +4,6 @@ require "rango"
4
4
  require "rango/templates/template"
5
5
 
6
6
  module Rango
7
- SubtemplateNotFound = Class.new(StandardError)
8
-
9
7
  module TemplateHelpers
10
8
  def self.extended(scope)
11
9
  class << scope
@@ -50,7 +48,7 @@ module Rango
50
48
  end
51
49
 
52
50
  def self.included(scope_class)
53
- scope_class.class_eval { attr_accessor :template }
51
+ scope_class.class_eval { attr_accessor :template}
54
52
  end
55
53
 
56
54
  # post/show.html: it's block is the block we like to see in output
@@ -90,14 +88,12 @@ module Rango
90
88
  # render "base.html"
91
89
  # render "./base.html"
92
90
  # render "../base.html"
93
- def render(path, context = Hash.new)
94
- full_path = normalize_template_path(path)
91
+ def render(template, context = Hash.new)
92
+ normalize_template_path(template)
95
93
  original_template = self.template
96
- template = Rango::Template.new(full_path, self) # self is scope
94
+ template = Rango::Template.new(template, self) # self is scope
97
95
  self.template = original_template
98
96
  return template.render(context)
99
- rescue Exceptions::TemplateNotFound # FIXME: this doesn't work
100
- raise SubtemplateNotFound, "Template #{path} doesn't exist in #{full_path}"
101
97
  end
102
98
 
103
99
  # partial "products/list"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rango
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1.pre
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Jakub \xC5\xA0\xC5\xA5astn\xC3\xBD aka Botanicus"
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain:
11
- date: 2010-02-15 00:00:00 +00:00
11
+ date: 2010-02-09 00:00:00 +00:00
12
12
  default_executable: rango
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
@@ -270,7 +270,6 @@ files:
270
270
  - lib/rango/helpers/assets.rb
271
271
  - lib/rango/helpers/general.rb
272
272
  - lib/rango/helpers/syntax.rb
273
- - lib/rango/mailer.rb
274
273
  - lib/rango/mini.rb
275
274
  - lib/rango/mini_render.rb
276
275
  - lib/rango/mixins/action_args.rb
@@ -455,7 +454,9 @@ has_rdoc: true
455
454
  homepage: http://github.com/botanicus/rango
456
455
  licenses: []
457
456
 
458
- post_install_message:
457
+ post_install_message: "[\e[32mVersion 0.2.1\e[0m] More inteligent environments handling, just use Rango.environment and it will detect the proper one from ENV[\"RACK_ENV\"], RACK_ENV constant or it will defaults to development. Rango.environment=(environment) will set all these variables so everything will stay consistent.\n\
458
+ [\e[32mVersion 0.2.1\e[0m] MongoMapper supported in stack generator (rango create stack blog --orm=mongomapper)\n\
459
+ [\e[32mVersion 0.2.1\e[0m] Added Rango::StackController which is more complete than just basic Rango::Controller\n"
459
460
  rdoc_options: []
460
461
 
461
462
  require_paths:
@@ -468,9 +469,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
468
469
  version:
469
470
  required_rubygems_version: !ruby/object:Gem::Requirement
470
471
  requirements:
471
- - - ">"
472
+ - - ">="
472
473
  - !ruby/object:Gem::Version
473
- version: 1.3.1
474
+ version: "0"
474
475
  version:
475
476
  requirements: []
476
477
 
data/lib/rango/mailer.rb DELETED
@@ -1,48 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require "net/smtp"
4
-
5
- # Mailer.new("noreply@rangoproject.org", "RangoProject.org")
6
- # self.to = "tony@example.com"
7
- # self.subject = "Just hey"
8
- # self.body = "Hey Tony, what's up?"
9
- # end
10
- module Rango
11
- class Mailer
12
- @@config = {smtp: ["localhost", 25]}
13
-
14
- def self.mail(options = Hash.new)
15
- self.new(options[:from]).tap do |mailer|
16
- mailer.body = options[:body]
17
- end
18
- end
19
-
20
- attr_accessor :to, :to_alias
21
- attr_accessor :from, :from_alias
22
- attr_accessor :body, :subject
23
-
24
- def initialize(from, from_alias = from, &block)
25
- @from, @from_alias = from, from_alias
26
- unless block.nil?
27
- block.instance_eval(&block)
28
- block.send
29
- end
30
- end
31
-
32
- def raw
33
- <<-EOF
34
- From: #{from_alias} <#{from}>
35
- To: #{to_alias} <#{to}>
36
- Subject: #{subject}
37
-
38
- #{body}
39
- EOF
40
- end
41
-
42
- def send(to)
43
- Net::SMTP.start(*@@config[:smtp]) do |smtp|
44
- smtp.send_message(self.raw, @from, to)
45
- end
46
- end
47
- end
48
- end