Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 373
- Log:
Initial import of Radiant 0.9.1, which is now packaged as a gem. This is an
import of the tagged 0.9.1 source checked out from GitHub, which isn't quite
the same as the gem distribution - but it doesn't seem to be available in an
archived form and the installed gem already has modifications, so this is
the closest I can get.
- Author:
- rool
- Date:
- Mon Mar 21 13:40:05 +0000 2011
- Size:
- 2926 Bytes
1 | require 'ostruct' |
2 | module Radiant |
3 | module ResourceResponses |
4 | def self.extended(base) |
5 | base.send :class_inheritable_writer, :responses |
6 | base.send :include, InstanceMethods |
7 | end |
8 | |
9 | def responses |
10 | r = (self.responses = read_inheritable_attribute(:responses) || Collector.new) |
11 | yield r if block_given? |
12 | r |
13 | end |
14 | |
15 | module InstanceMethods |
16 | def response_for(action) |
17 | responses = self.class.responses.send(action) |
18 | respond_to do |wants| |
19 | responses.each_format do |f, format_block| |
20 | if format_block |
21 | wants.send(f, &wrap(format_block)) |
22 | else |
23 | wants.send(f) |
24 | end |
25 | end |
26 | responses.each_published do |pub, pub_block| |
27 | wants.send(pub, &wrap(pub_block)) |
28 | end |
29 | if responses.default |
30 | wants.any(&wrap(responses.default)) |
31 | else |
32 | wants.any |
33 | end |
34 | end |
35 | end |
36 | |
37 | def wrap(proc) |
38 | # Makes sure our response blocks get evaluated in the right context |
39 | lambda do |
40 | instance_eval(&proc) |
41 | end |
42 | end |
43 | end |
44 | |
45 | class Collector < OpenStruct |
46 | def initialize |
47 | super |
48 | @table = Hash.new {|h,k| h[k] = Response.new } |
49 | end |
50 | |
51 | def initialize_copy(orig) |
52 | super |
53 | @table.keys.each do |key| |
54 | @table[key] = orig.send(key).dup |
55 | end |
56 | end |
57 | end |
58 | |
59 | class Response |
60 | attr_reader :publish_formats, :publish_block, :blocks, :block_order |
61 | def initialize |
62 | @publish_formats = [] |
63 | @blocks = {} |
64 | @block_order = [] |
65 | end |
66 | |
67 | def initialize_copy(orig) |
68 | @publish_formats = orig.publish_formats.dup |
69 | @blocks = orig.blocks.dup |
70 | @block_order = orig.block_order.dup |
71 | @publish_block = orig.publish_block.dup if orig.publish_block |
72 | @default = orig.default.dup if orig.default |
73 | end |
74 | |
75 | def default(&block) |
76 | if block_given? |
77 | @default = block |
78 | end |
79 | @default |
80 | end |
81 | |
82 | def publish(*formats, &block) |
83 | @publish_formats.concat(formats) |
84 | if block_given? |
85 | @publish_block = block |
86 | else |
87 | raise ArgumentError, "Block required to publish" unless @publish_block |
88 | end |
89 | end |
90 | |
91 | def each_published |
92 | publish_formats.each do |format| |
93 | yield format, publish_block if block_given? |
94 | end |
95 | end |
96 | |
97 | def each_format |
98 | @block_order.each do |format| |
99 | yield format, @blocks[format] if block_given? |
100 | end |
101 | end |
102 | |
103 | def method_missing(method, *args, &block) |
104 | if block_given? |
105 | @blocks[method] = block |
106 | @block_order << method unless @block_order.include?(method) |
107 | elsif args.empty? |
108 | @block_order << method |
109 | else |
110 | super |
111 | end |
112 | end |
113 | end |
114 | end |
115 | end |