trellis 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -38,6 +38,7 @@ require 'markaby'
38
38
  require 'redcloth'
39
39
  require 'bluecloth'
40
40
  require 'english/inflect'
41
+ require 'facets'
41
42
  require 'directory_watcher'
42
43
 
43
44
  module Trellis
@@ -113,7 +114,7 @@ module Trellis
113
114
  response = Rack::Response.new
114
115
  request = Rack::Request.new(env)
115
116
 
116
- Application.logger.debug "request received with url_root of #{request.script_name}"
117
+ Application.logger.debug "request received with url_root of #{request.script_name}" if request.script_name
117
118
 
118
119
  session = env["rack.session"]
119
120
 
@@ -132,6 +133,8 @@ module Trellis
132
133
  router.inject_parameters_into_page_instance(page, request)
133
134
  result = route.event ? page.process_event(route.event, route.value, route.source, session) : page
134
135
 
136
+ Application.logger.debug "response is #{result} an instance of #{result.class}"
137
+
135
138
  # prepare the http response
136
139
  if (request.post? || route.event) && result.kind_of?(Trellis::Page)
137
140
  # for action events of posts then use redirect after post pattern
@@ -139,6 +142,7 @@ module Trellis
139
142
  path = result.path ? result.path.gsub(/\/events\/.*/, '') : result.class.class_to_sym
140
143
  response.status = 302
141
144
  response.headers["Location"] = "#{request.script_name}/#{path}"
145
+ Application.logger.debug "redirecting to ==> #{request.script_name}/#{path}"
142
146
  else
143
147
  # for render requests simply render the page
144
148
  response.body = result.kind_of?(Trellis::Page) ? result.render : result
@@ -319,7 +323,8 @@ module Trellis
319
323
  attr_accessor :params, :path, :logger
320
324
 
321
325
  def self.inherited(child) #:nodoc:
322
- @@subclasses[child.class_to_sym] = child
326
+ sym = child.class_to_sym
327
+ @@subclasses[sym] = child if sym
323
328
 
324
329
  child.instance_variable_set(:@name, child.underscore_class_name)
325
330
  child.attr_array(:pages, :create_accessor => false)
@@ -451,14 +456,33 @@ module Trellis
451
456
  def self.inject_dependent_pages(target)
452
457
  @pages.each do |sym|
453
458
  clazz = Page.get_page(sym)
454
- if clazz
455
- Application.logger.debug "injecting an instance of #{clazz} for #{sym}"
456
- target.instance_variable_set("@#{sym}".to_sym, clazz.new)
457
- target.meta_def(sym) { instance_variable_get("@#{sym}") }
458
- else
459
- # throw an exception in production mode or
460
- # dynamically generate a page in development mode
459
+ # if the injected page class is not found
460
+ # throw an exception in production mode or
461
+ # dynamically generate a page in development mode
462
+ unless clazz
463
+ target_class = sym.to_s.camelcase(:upper)
464
+ Application.logger.debug "creating stand in page class #{target_class} for symbol #{sym}"
465
+
466
+ clazz = Page.create_child(target_class) do
467
+
468
+ def method_missing(sym, *args, &block)
469
+ Application.logger.debug "faking response to #{sym}(#{args}) from #{self} an instance of #{self.class}"
470
+ self
471
+ end
472
+
473
+ template do
474
+ xhtml_strict {
475
+ head { title "Stand-in Page" }
476
+ body { h1 { text %[Stand-in Page for <trellis:value name="page_name"/>] }}
477
+ }
478
+ end
479
+ end
480
+ Page.subclasses[sym] = clazz
461
481
  end
482
+
483
+ Application.logger.debug "injecting an instance of #{clazz} for #{sym}"
484
+ target.instance_variable_set("@#{sym}".to_sym, clazz.new)
485
+ target.meta_def(sym) { instance_variable_get("@#{sym}") }
462
486
  end
463
487
  end
464
488
 
@@ -600,6 +624,9 @@ module Trellis
600
624
  end
601
625
  end
602
626
 
627
+ # add other useful values to the tag context
628
+ @context.globals.send(:page_name=, page.class.to_s)
629
+
603
630
  #TODO add public page methods to the context
604
631
 
605
632
 
data/lib/trellis/utils.rb CHANGED
@@ -50,7 +50,8 @@ class Class #:nodoc:
50
50
  end
51
51
 
52
52
  def underscore_class_name
53
- name.to_s.gsub(/::/, '/').
53
+ value = (name.empty? || name =~ /<class:(.*)/) ? self : name
54
+ value.to_s.gsub(/::/, '/').
54
55
  gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
55
56
  gsub(/([a-z\d])([A-Z])/,'\1_\2').
56
57
  tr("-", "_").
@@ -87,6 +88,14 @@ class Class #:nodoc:
87
88
  instance_variable_set("@#{plural_array_name_sym}".to_sym, Array.new)
88
89
  meta_def(plural_array_name_sym) { instance_variable_get("@#{plural_array_name_sym}".to_sym) } if create_accessor
89
90
  end
91
+
92
+ def create_child(class_name, mod = Object, register = true, &block)
93
+ klass = Class.new self
94
+ klass.class_eval &block if block_given?
95
+ mod.const_set class_name, klass if register
96
+ klass
97
+ end
98
+
90
99
  end
91
100
 
92
101
  class String #:nodoc:
@@ -28,7 +28,7 @@ module Trellis
28
28
  module VERSION #:nodoc:
29
29
  MAJOR = 0
30
30
  MINOR = 0
31
- TINY = 3
31
+ TINY = 4
32
32
 
33
33
  STRING = [MAJOR, MINOR, TINY].join('.')
34
34
  end
@@ -48,6 +48,13 @@ describe Class, " when calling underscore_class_name" do
48
48
  sym = Boo::SomeOtherClass.underscore_class_name
49
49
  sym.should eql("some_other_class")
50
50
  end
51
+
52
+ it "should return a valid underscore ruby identifier string for an annonymous class" do
53
+ class TheParent; end
54
+ TheParent.create_child "AnnonymousChild"
55
+ sym = AnnonymousChild.underscore_class_name
56
+ sym.should eql("annonymous_child")
57
+ end
51
58
  end
52
59
 
53
60
  # class_to_sym
@@ -66,6 +73,13 @@ describe Class, " when calling class_to_sym" do
66
73
  sym = Boo::SomeOtherClass.class_to_sym
67
74
  sym.should eql(:some_other_class)
68
75
  end
76
+
77
+ it "should return a valid underscore ruby identifier as a symbol for an annonymous class" do
78
+ class TheParent; end
79
+ TheParent.create_child "AnotherAnnonymousChild"
80
+ sym = AnotherAnnonymousChild.class_to_sym
81
+ sym.should eql(:another_annonymous_child)
82
+ end
69
83
  end
70
84
 
71
85
  # attr_array tests
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trellis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Sam-Bodden
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-29 00:00:00 -07:00
12
+ date: 2009-10-06 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency