wagn 1.13.0.pre1 → 1.13.0.pre2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/app/controllers/card_controller.rb +3 -3
- data/db/migrate_cards/20140307231621_user_data_to_cards.rb +5 -1
- data/lib/card.rb +5 -7
- data/lib/card/chunk.rb +1 -0
- data/lib/card/codename.rb +48 -31
- data/lib/card/env.rb +0 -1
- data/lib/card/exceptions.rb +3 -3
- data/lib/card/format.rb +89 -166
- data/lib/card/generators/set/USAGE +1 -1
- data/lib/card/loader.rb +1 -1
- data/lib/card/set.rb +196 -112
- data/lib/card/set_pattern.rb +37 -71
- data/lib/wagn/cache.rb +8 -7
- data/lib/wagn/commands.rb +1 -1
- data/lib/wagn/config/environments/development.rb +1 -1
- data/lib/wagn/config/initializers/paperclip.rb +1 -0
- data/lib/wagn/generators/wagn/templates/Gemfile +59 -55
- data/lib/wagn/location.rb +2 -2
- data/mods/core/formats/html_format.rb +2 -6
- data/mods/core/formats/text_format.rb +1 -1
- data/mods/core/set_patterns/01_all.rb +0 -5
- data/mods/core/set_patterns/02_all_plus.rb +1 -3
- data/mods/core/set_patterns/07_type_plus_right.rb +0 -1
- data/mods/core/sets/all/active_card.rb +1 -1
- data/mods/core/sets/all/name.rb +3 -2
- data/mods/core/sets/all/pattern.rb +9 -23
- data/mods/core/sets/all/phases.rb +27 -13
- data/mods/core/sets/all/rules.rb +3 -3
- data/mods/core/sets/all/templating.rb +5 -2
- data/mods/core/sets/all/tracked_attributes.rb +2 -1
- data/mods/core/sets/right/structure.rb +13 -0
- data/mods/{standard → core}/sets/type/plain_text.rb +0 -0
- data/mods/standard/formats/email_html_format.rb +1 -1
- data/mods/standard/lib/card/machine.rb +16 -12
- data/mods/standard/lib/card/machine_input.rb +1 -1
- data/mods/standard/sets/all/attach.rb +1 -1
- data/mods/standard/sets/all/base.rb +92 -94
- data/mods/standard/sets/all/follow.rb +1 -1
- data/mods/standard/sets/all/rich_html.rb +5 -3
- data/mods/standard/sets/all/rss.rb +12 -5
- data/mods/standard/sets/right/account.rb +1 -1
- data/mods/standard/sets/right/add_help.rb +3 -1
- data/mods/standard/sets/right/comment.rb +92 -3
- data/mods/standard/sets/right/create.rb +2 -87
- data/mods/standard/sets/right/default.rb +3 -2
- data/mods/standard/sets/right/delete.rb +2 -5
- data/mods/standard/sets/right/help.rb +3 -1
- data/mods/standard/sets/right/machine_output.rb +9 -7
- data/mods/standard/sets/right/read.rb +2 -5
- data/mods/standard/sets/right/style.rb +3 -2
- data/mods/standard/sets/right/update.rb +2 -5
- data/mods/standard/sets/rstar/rules.rb +0 -2
- data/mods/standard/sets/self/head.rb +2 -3
- data/mods/standard/sets/self/navbox.rb +0 -7
- data/mods/standard/sets/self/recent.rb +2 -2
- data/mods/standard/sets/self/search.rb +10 -3
- data/mods/standard/sets/self/signin.rb +3 -3
- data/mods/standard/sets/type/cardtype.rb +2 -2
- data/mods/standard/sets/type/coffee_script.rb +4 -4
- data/mods/standard/sets/type/css.rb +12 -4
- data/mods/standard/sets/type/image.rb +19 -19
- data/mods/standard/sets/type/java_script.rb +1 -1
- data/mods/standard/sets/type/layout_type.rb +3 -2
- data/mods/standard/sets/type/pointer.rb +3 -2
- data/mods/standard/sets/type/scss.rb +6 -34
- data/mods/standard/sets/type/search_type.rb +22 -16
- data/mods/standard/sets/type/set.rb +2 -2
- data/mods/standard/sets/type/setting.rb +2 -2
- data/mods/standard/sets/type/skin.rb +4 -18
- data/spec/controllers/card_controller_spec.rb +2 -2
- data/spec/lib/card/flexmail_spec.rb +1 -0
- data/spec/lib/card/format_spec.rb +9 -9
- data/spec/lib/card/loader_spec.rb +1 -2
- data/spec/lib/card/name_spec.rb +7 -1
- data/spec/lib/card/set_pattern_spec.rb +5 -5
- data/spec/mods/core/sets/all/pattern_spec.rb +0 -9
- data/spec/mods/core/sets/all/phases_spec.rb +2 -1
- data/spec/mods/standard/lib/machine_input_spec.rb +20 -4
- data/spec/mods/standard/lib/machine_spec.rb +64 -14
- data/spec/mods/standard/sets/right/machine_output_spec.rb +2 -17
- data/spec/mods/standard/sets/right/script_spec.rb +9 -5
- data/spec/mods/standard/sets/right/style_spec.rb +11 -5
- data/spec/mods/standard/sets/type/coffeescript_spec.rb +5 -7
- data/spec/mods/standard/sets/type/css_spec.rb +3 -4
- data/spec/mods/standard/sets/type/javascript_spec.rb +3 -5
- data/spec/mods/standard/sets/type/scss_spec.rb +4 -7
- data/spec/mods/standard/sets/type/skin_spec.rb +29 -8
- metadata +5 -4
- data/mods/standard/sets/right/structure.rb +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b8faf3945e01dfc7e56a2b1edb8b1f3e2ef1b033
|
4
|
+
data.tar.gz: 3cdc4a0268f4352f583822daae068459f07ae855
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00098a43f7e3956d1f653660b67f9df87a7ec0120e80edd9ee83047bbd263bc1cc5d96f5c33b7bcbcdb09be6a6d83533583d9a69bc278bcbd2de3387b5dc1fb9
|
7
|
+
data.tar.gz: 61f0a6c1bbad7a336f7cfae12e059a34d67dd55f6e22609a38117d8eeea8b446d0e37b8b1f62d8ab597faff45f702132879488634010bf14795ec2b2545a50a6
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.13.0.
|
1
|
+
1.13.0.pre2
|
@@ -138,7 +138,7 @@ class CardController < ActionController::Base
|
|
138
138
|
end
|
139
139
|
end
|
140
140
|
@card.selected_revision_id = params[:rev].to_i if params[:rev]
|
141
|
-
|
141
|
+
|
142
142
|
Card::Env[:main_name] = params[:main] || (card && card.name) || ''
|
143
143
|
render_errors if card.errors.any?
|
144
144
|
true
|
@@ -252,7 +252,7 @@ class CardController < ActionController::Base
|
|
252
252
|
end
|
253
253
|
|
254
254
|
|
255
|
-
rescue_from
|
255
|
+
rescue_from StandardError do |exception|
|
256
256
|
Rails.logger.info "exception = #{exception.class}: #{exception.message}"
|
257
257
|
|
258
258
|
@card ||= Card.new
|
@@ -262,7 +262,7 @@ class CardController < ActionController::Base
|
|
262
262
|
## some are redundantly defined in view
|
263
263
|
when Card::Oops, Card::Query
|
264
264
|
card.errors.add :exception, exception.message
|
265
|
-
#
|
265
|
+
# these error messages are visible to end users and are generally not treated as bugs.
|
266
266
|
# Probably want to rename accordingly.
|
267
267
|
:errors
|
268
268
|
when Card::PermissionDenied, Wagn::PermissionDenied
|
@@ -59,7 +59,11 @@ class UserDataToCards < ActiveRecord::Migration
|
|
59
59
|
cardname = "#{base.name}+#{Card[:account].name}+#{Card[field].name}"
|
60
60
|
user_field = ( field==:password ? :crypted_password : field )
|
61
61
|
if content = user.send( user_field )
|
62
|
-
|
62
|
+
begin
|
63
|
+
Card.create! date_args.merge( :name=>cardname, :content=>content)
|
64
|
+
rescue => e
|
65
|
+
puts "error importing #{cardname}: #{e.message}"
|
66
|
+
end
|
63
67
|
end
|
64
68
|
end
|
65
69
|
end
|
data/lib/card.rb
CHANGED
@@ -1,34 +1,31 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
|
3
3
|
class Card < ActiveRecord::Base
|
4
|
+
|
4
5
|
require_dependency 'card/active_record_ext'
|
5
|
-
|
6
6
|
require_dependency 'card/codename'
|
7
7
|
require_dependency 'card/query'
|
8
|
-
require_dependency 'card/set_pattern'
|
8
|
+
require_dependency 'card/set_pattern'
|
9
9
|
require_dependency 'card/set'
|
10
10
|
require_dependency 'card/format'
|
11
11
|
require_dependency 'card/exceptions'
|
12
12
|
require_dependency 'card/auth'
|
13
13
|
require_dependency 'card/loader'
|
14
14
|
|
15
|
-
extend Set
|
16
|
-
|
17
15
|
has_many :revisions, :order => :id
|
18
16
|
has_many :references_from, :class_name => :Reference, :foreign_key => :referee_id
|
19
17
|
has_many :references_to, :class_name => :Reference, :foreign_key => :referer_id
|
20
18
|
|
21
|
-
cache_attributes 'name', 'type_id' #
|
19
|
+
cache_attributes 'name', 'type_id' # review - still worth it in Rails 3?
|
22
20
|
|
23
21
|
cattr_accessor :set_patterns, :error_codes
|
24
22
|
@@set_patterns, @@error_codes = [], {}
|
25
23
|
|
26
24
|
attr_writer :selected_revision_id #writer because read method is in mod (and does not override upon load)
|
27
|
-
attr_accessor :action, :supercard,
|
25
|
+
attr_accessor :action, :supercard,
|
28
26
|
:comment, :comment_author, # obviated soon
|
29
27
|
:update_referencers # wrong mechanism for this
|
30
28
|
|
31
|
-
|
32
29
|
define_callbacks :approve, :store, :extend
|
33
30
|
|
34
31
|
before_validation :approve
|
@@ -40,3 +37,4 @@ class Card < ActiveRecord::Base
|
|
40
37
|
tracks :content # we can phase this out and just use "dirty" handling once current content is stored in the cards table
|
41
38
|
|
42
39
|
end
|
40
|
+
|
data/lib/card/chunk.rb
CHANGED
@@ -47,6 +47,7 @@ class Card
|
|
47
47
|
register_list :default, [ :URI, :HostURI, :EmailURI, :EscapedLiteral, :Include, :Link ]
|
48
48
|
register_list :references, [ :EscapedLiteral, :Include, :Link ]
|
49
49
|
register_list :inclusion_only, [ :Include ]
|
50
|
+
register_list :inclusion_and_link, [ :Include, :Link ]
|
50
51
|
|
51
52
|
class Abstract
|
52
53
|
class_attribute :config
|
data/lib/card/codename.rb
CHANGED
@@ -1,47 +1,64 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
|
3
|
-
class Card
|
3
|
+
class Card
|
4
|
+
class Codename
|
4
5
|
|
5
|
-
|
6
|
+
@@codehash=nil
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
class << self
|
9
|
+
# returns codename for id and vice versa. not in love with this api --efm
|
10
|
+
def [] key
|
11
|
+
if !key.nil?
|
12
|
+
key = key.to_sym unless Integer===key
|
13
|
+
codehash[key]
|
14
|
+
end
|
13
15
|
end
|
14
|
-
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
def codehash
|
18
|
+
@@codehash || load_hash
|
19
|
+
end
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
def reset_cache
|
22
|
+
@@codehash = nil
|
23
|
+
end
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
#only used in migration
|
26
|
+
def bootdata hash
|
27
|
+
@@codehash = hash
|
28
|
+
end
|
28
29
|
|
29
30
|
|
30
|
-
|
31
|
+
private
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
33
|
+
def load_hash
|
34
|
+
@@codehash = {}
|
35
|
+
sql = 'select id, codename from cards where codename is not NULL'
|
36
|
+
ActiveRecord::Base.connection.select_all(sql).each do |row|
|
37
|
+
#FIXME: remove duplicate checks, put them in other tools
|
38
|
+
code, cid = row['codename'].to_sym, row['id'].to_i
|
39
|
+
if @@codehash.has_key?(code) or @@codehash.has_key?(cid)
|
40
|
+
warn "dup code ID:#{cid} (#{@@codehash[code]}), CD:#{code} (#{@@codehash[cid]})"
|
41
|
+
end
|
42
|
+
@@codehash[code] = cid; @@codehash[cid] = code
|
40
43
|
end
|
41
|
-
@@codehash[code] = cid; @@codehash[cid] = code
|
42
|
-
end
|
43
44
|
|
44
|
-
|
45
|
+
@@codehash
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
def self.const_missing const
|
53
|
+
if const.to_s =~ /^([A-Z]\S*)ID$/ and code=$1.underscore.to_sym
|
54
|
+
if card_id = Codename[code]
|
55
|
+
const_set const, card_id
|
56
|
+
else
|
57
|
+
raise "Missing codename #{code} (#{const})"
|
58
|
+
end
|
59
|
+
else
|
60
|
+
super
|
45
61
|
end
|
46
62
|
end
|
63
|
+
|
47
64
|
end
|
data/lib/card/env.rb
CHANGED
data/lib/card/exceptions.rb
CHANGED
@@ -4,7 +4,7 @@ class Card
|
|
4
4
|
class Error < StandardError #code problem
|
5
5
|
end
|
6
6
|
|
7
|
-
class Oops < Error # wagneer problem
|
7
|
+
class Oops < Error # wagneer problem (rename!)
|
8
8
|
end
|
9
9
|
|
10
10
|
class BadQuery < Error
|
@@ -27,10 +27,10 @@ class Card
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
class Abort <
|
30
|
+
class Abort < StandardError
|
31
31
|
attr_reader :status
|
32
32
|
|
33
|
-
def initialize status
|
33
|
+
def initialize status, msg=''
|
34
34
|
@status = status
|
35
35
|
super msg
|
36
36
|
end
|
data/lib/card/format.rb
CHANGED
@@ -9,14 +9,14 @@ class Card
|
|
9
9
|
:layout=>:layout, :new=>:edit, :setup=>:edit, :normal=>:normal, :template=>:template } #should be set in views
|
10
10
|
|
11
11
|
cattr_accessor :ajax_call, :registered, :max_depth
|
12
|
-
[ :perms, :denial_views, :
|
12
|
+
[ :perms, :denial_views, :error_codes, :view_tags, :aliases ].each do |acc|
|
13
13
|
cattr_accessor acc
|
14
14
|
self.send "#{acc}=", {}
|
15
15
|
end
|
16
16
|
@@max_char_count = 200 #should come from Wagn.config
|
17
17
|
@@max_depth = 20 # ditto
|
18
18
|
|
19
|
-
attr_reader :card, :root, :parent, :
|
19
|
+
attr_reader :card, :root, :parent, :main_opts
|
20
20
|
attr_accessor :form, :error_status, :inclusion_opts
|
21
21
|
|
22
22
|
class << self
|
@@ -25,77 +25,16 @@ class Card
|
|
25
25
|
def register format
|
26
26
|
@@registered << format.to_s
|
27
27
|
end
|
28
|
-
|
29
|
-
def
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
def view view, *args, &final
|
35
|
-
view = view.to_name.key.to_sym
|
36
|
-
if block_given?
|
37
|
-
define_view view, args[0], &final
|
38
|
-
else
|
39
|
-
opts = Hash===args[0] ? args.shift : nil
|
40
|
-
alias_view view, opts, args.shift
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def define_view view, opts, &final
|
45
|
-
opts ||= {}
|
46
|
-
opts.merge! Card::Set.current[:opts]
|
47
|
-
|
48
|
-
extract_class_vars view, opts
|
49
|
-
view_key = get_set_key view, opts
|
50
|
-
|
51
|
-
define_method "_final_#{view_key}", &final
|
52
|
-
define_render_methods view
|
53
|
-
end
|
54
|
-
|
55
|
-
def alias_view alias_view, opts, referent_view=nil
|
56
|
-
subset_views[alias_view] = true if opts && !opts.empty?
|
57
|
-
|
58
|
-
referent_view ||= alias_view
|
59
|
-
alias_opts = Card::Set.current[:opts]
|
60
|
-
referent_view_key = get_set_key referent_view, (opts || alias_opts)
|
61
|
-
alias_view_key = get_set_key alias_view, alias_opts
|
62
|
-
|
63
|
-
define_method "_final_#{alias_view_key}" do |*a|
|
64
|
-
send "_final_#{referent_view_key}", *a
|
65
|
-
end
|
66
|
-
define_render_methods alias_view
|
67
|
-
end
|
68
|
-
|
69
|
-
def define_render_methods view
|
70
|
-
# note: this could also be done with method_missing. is this any faster?
|
71
|
-
if !method_defined? "render_#{view}"
|
72
|
-
define_method "_render_#{view}" do |*a|
|
73
|
-
send_final_render_method view, *a
|
74
|
-
end
|
75
|
-
|
76
|
-
define_method "render_#{view}" do |*a|
|
77
|
-
send "_render_#{ ok_view view, *a }", *a
|
78
|
-
end
|
79
|
-
end
|
28
|
+
|
29
|
+
def format_class_name format
|
30
|
+
f = format.to_s
|
31
|
+
f = @@aliases[ f ] || f
|
32
|
+
"#{ f.camelize }Format"
|
80
33
|
end
|
81
|
-
|
82
34
|
|
83
|
-
|
84
35
|
|
85
|
-
def new card, opts={}
|
86
|
-
klass = self != Format ? self : get_format( (opts[:format] || :html).to_sym )
|
87
|
-
new_format = klass.allocate
|
88
|
-
new_format.send :initialize, card, opts
|
89
|
-
new_format
|
90
|
-
end
|
91
|
-
|
92
|
-
def tagged view, tag
|
93
|
-
view and tag and view_tags = @@view_tags[view.to_sym] and view_tags[tag.to_sym]
|
94
|
-
end
|
95
|
-
|
96
|
-
private
|
97
|
-
|
98
36
|
def extract_class_vars view, opts
|
37
|
+
return unless opts.present?
|
99
38
|
perms[view] = opts.delete(:perms) if opts[:perms]
|
100
39
|
error_codes[view] = opts.delete(:error_code) if opts[:error_code]
|
101
40
|
denial_views[view]= opts.delete(:denial) if opts[:denial]
|
@@ -106,43 +45,62 @@ class Card
|
|
106
45
|
view_tags[view][tag] = true
|
107
46
|
end
|
108
47
|
end
|
109
|
-
|
110
|
-
|
111
|
-
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
def new card, opts={}
|
52
|
+
if self != Format
|
53
|
+
super
|
54
|
+
else
|
55
|
+
klass = Card.const_get format_class_name( opts[:format] || :html )
|
56
|
+
self == klass ? super : klass.new( card, opts )
|
112
57
|
end
|
113
58
|
end
|
59
|
+
|
60
|
+
def tagged view, tag
|
61
|
+
view and tag and view_tags = @@view_tags[view.to_sym] and view_tags[tag.to_sym]
|
62
|
+
end
|
63
|
+
|
114
64
|
|
115
|
-
def
|
116
|
-
|
117
|
-
|
65
|
+
def format_ancestry
|
66
|
+
ancestry = [ self ]
|
67
|
+
unless self == Card::Format
|
68
|
+
ancestry = ancestry + superclass.format_ancestry
|
118
69
|
end
|
119
|
-
|
120
|
-
#warn "gvkey #{selection_key}, #{opts.inspect} R:#{key}"
|
121
|
-
key.to_sym
|
70
|
+
ancestry
|
122
71
|
end
|
72
|
+
|
123
73
|
end
|
124
74
|
|
125
75
|
|
126
76
|
#~~~~~ INSTANCE METHODS
|
127
77
|
|
128
78
|
def initialize card, opts={}
|
129
|
-
@card = card
|
79
|
+
@card = card or raise Card::Error, "format initialized without card"
|
130
80
|
opts.each do |key, value|
|
131
81
|
instance_variable_set "@#{key}", value
|
132
82
|
end
|
133
83
|
|
134
|
-
@mode
|
135
|
-
@
|
136
|
-
@root
|
137
|
-
@vars = {}
|
84
|
+
@mode ||= :normal
|
85
|
+
@depth ||= 0
|
86
|
+
@root ||= self
|
138
87
|
|
139
88
|
@context_names ||= if params[:slot] && context_name_list = params[:slot][:name_context]
|
140
89
|
context_name_list.split(',').map &:to_name
|
141
90
|
else [] end
|
91
|
+
|
92
|
+
include_set_format_modules
|
93
|
+
self
|
142
94
|
end
|
143
95
|
|
144
|
-
|
145
|
-
|
96
|
+
def include_set_format_modules
|
97
|
+
self.class.format_ancestry.reverse.each do |klass|
|
98
|
+
card.set_format_modules( klass ).each do |m|
|
99
|
+
singleton_class.send :include, m
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
146
104
|
def inclusion_defaults
|
147
105
|
@inclusion_defaults ||= begin
|
148
106
|
defaults = get_inclusion_defaults.clone
|
@@ -196,11 +154,22 @@ class Card
|
|
196
154
|
end
|
197
155
|
end
|
198
156
|
|
199
|
-
def method_missing
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
157
|
+
def method_missing method, *opts, &proc
|
158
|
+
case method
|
159
|
+
when /(_)?(optional_)?render(_(\w+))?/
|
160
|
+
view = $3 ? $4 : opts.shift
|
161
|
+
args = opts[0] ? opts.shift.clone : {}
|
162
|
+
args.merge!( :optional=>true, :default_visibility=>opts.shift) if $2
|
163
|
+
args[ :skip_permissions ] = true if $1
|
164
|
+
render view, args
|
165
|
+
when /^_view_(\w+)/
|
166
|
+
view = @current_view || $1
|
167
|
+
unsupported_view view
|
168
|
+
else
|
169
|
+
proc = proc { |*a| raw yield *a } if proc
|
170
|
+
response = root.template.send method, *opts, &proc
|
171
|
+
String===response ? root.template.raw( response ) : response
|
172
|
+
end
|
204
173
|
end
|
205
174
|
|
206
175
|
#
|
@@ -210,33 +179,20 @@ class Card
|
|
210
179
|
|
211
180
|
|
212
181
|
def render view, args={}
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
end
|
220
|
-
end
|
221
|
-
|
222
|
-
def _render view, args={}
|
223
|
-
args[:allowed] = true
|
224
|
-
render view, args
|
225
|
-
end
|
226
|
-
|
227
|
-
def optional_render view, args, default=:show
|
228
|
-
if show_view? view, args, default
|
229
|
-
view = args["optional_#{ canonicalize_view view }_view".to_sym] || view
|
230
|
-
render view, args
|
182
|
+
unless args.delete(:optional) && !show_view?( view, args )
|
183
|
+
@current_view = view = ok_view canonicalize_view( view ), args
|
184
|
+
args = default_render_args view, args
|
185
|
+
with_inclusion_mode view do
|
186
|
+
send "_view_#{ view }", args
|
187
|
+
end
|
231
188
|
end
|
189
|
+
rescue => e
|
190
|
+
rescue_view e, view
|
232
191
|
end
|
233
192
|
|
234
|
-
def _optional_render view, args, default=:show
|
235
|
-
args[:allowed] = true
|
236
|
-
optional_render view, args, default
|
237
|
-
end
|
238
193
|
|
239
|
-
def show_view? view, args
|
194
|
+
def show_view? view, args
|
195
|
+
default = args.delete(:default_visibility) || :show #FIXME - ugly
|
240
196
|
view_key = canonicalize_view view
|
241
197
|
api_option = args["optional_#{ view_key }".to_sym]
|
242
198
|
case
|
@@ -267,24 +223,6 @@ class Card
|
|
267
223
|
end
|
268
224
|
|
269
225
|
|
270
|
-
def send_final_render_method view, *a
|
271
|
-
@current_view = view
|
272
|
-
args = default_render_args view, *a
|
273
|
-
if final_method = view_method(view)
|
274
|
-
with_inclusion_mode view do
|
275
|
-
send final_method, args
|
276
|
-
end
|
277
|
-
else
|
278
|
-
unsupported_view view
|
279
|
-
end
|
280
|
-
rescue Exception=>e
|
281
|
-
if Rails.env =~ /^cucumber|test$/
|
282
|
-
raise e
|
283
|
-
else
|
284
|
-
rescue_view e, view
|
285
|
-
end
|
286
|
-
end
|
287
|
-
|
288
226
|
def default_render_args view, a=nil
|
289
227
|
args = case a
|
290
228
|
when nil ; {}
|
@@ -303,20 +241,20 @@ class Card
|
|
303
241
|
|
304
242
|
|
305
243
|
def rescue_view e, view
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
244
|
+
if Rails.env =~ /^cucumber|test$/
|
245
|
+
raise e
|
246
|
+
else
|
247
|
+
controller.send :notify_airbrake, e if Airbrake.configuration.api_key
|
248
|
+
Rails.logger.info "\nError rendering #{error_cardname} / #{view}: #{e.class} : #{e.message}"
|
249
|
+
Rails.logger.debug "BT: #{e.backtrace*"\n "}"
|
250
|
+
rendering_error e, view
|
251
|
+
end
|
310
252
|
end
|
311
253
|
|
312
254
|
def error_cardname
|
313
255
|
card && card.name.present? ? card.name : 'unknown card'
|
314
256
|
end
|
315
257
|
|
316
|
-
def unknown_view view
|
317
|
-
"unknown view: #{view}"
|
318
|
-
end
|
319
|
-
|
320
258
|
def unsupported_view view
|
321
259
|
"view (#{view}) not supported for #{error_cardname}"
|
322
260
|
end
|
@@ -330,21 +268,13 @@ class Card
|
|
330
268
|
#
|
331
269
|
|
332
270
|
def subformat subcard
|
333
|
-
#should consider calling "child"
|
334
271
|
subcard = Card.fetch( subcard, :new=>{} ) if String===subcard
|
335
|
-
sub = self.
|
336
|
-
|
272
|
+
sub = self.class.new subcard, :parent=>self, :depth=>@depth+1, :root=>@root,
|
273
|
+
# FIXME - the following four should not be hard-coded here. need a generalized mechanism
|
274
|
+
# for attribute inheritance
|
275
|
+
:context_names=>@context_names, :mode=>@mode, :mainline=>@mainline, :form=>@form
|
337
276
|
end
|
338
277
|
|
339
|
-
def initialize_subformat subcard, parent
|
340
|
-
@parent = parent
|
341
|
-
@card = subcard
|
342
|
-
@vars = {}
|
343
|
-
@char_count = 0
|
344
|
-
@depth += 1
|
345
|
-
@inclusion_defaults = @inclusion_opts = @showname = @ok = nil
|
346
|
-
self
|
347
|
-
end
|
348
278
|
|
349
279
|
def process_content content=nil, opts={}
|
350
280
|
process_content_object(content, opts).to_s
|
@@ -352,18 +282,19 @@ class Card
|
|
352
282
|
|
353
283
|
def process_content_object content=nil, opts={}
|
354
284
|
return content unless card
|
355
|
-
content = card.
|
285
|
+
content = card.raw_content || '' if content.nil?
|
356
286
|
|
357
287
|
obj_content = Card::Content===content ? content : Card::Content.new( content, format=self )
|
358
288
|
|
359
|
-
card.update_references( obj_content, true ) if card.references_expired # I thik we need this generalized
|
289
|
+
card.update_references( obj_content, refresh=true ) if card.references_expired # I thik we need this generalized
|
360
290
|
|
361
291
|
obj_content.process_content_object do |chunk_opts|
|
362
292
|
prepare_nest chunk_opts.merge(opts) { yield }
|
363
293
|
end
|
364
294
|
end
|
365
295
|
|
366
|
-
def ok_view view, args={}
|
296
|
+
def ok_view view, args={}
|
297
|
+
return view if args.delete :skip_permissions
|
367
298
|
approved_view = case
|
368
299
|
when @depth >= @@max_depth ; :too_deep # prevent recursion. @depth tracks subformats
|
369
300
|
when @@perms[view] == :none ; view # view requires no permissions
|
@@ -417,17 +348,7 @@ class Card
|
|
417
348
|
DEPRECATED_VIEWS[view_key] || view_key
|
418
349
|
end
|
419
350
|
end
|
420
|
-
|
421
|
-
def view_method view
|
422
|
-
return "_final_#{view}" unless card && @@subset_views[view]
|
423
|
-
card.method_keys.each do |method_key|
|
424
|
-
meth = "_final_"+(method_key.blank? ? "#{view}" : "#{method_key}_#{view}")
|
425
|
-
#warn "looking up #{method_key}, M:#{meth} for #{card.name}"
|
426
|
-
return meth if respond_to?(meth.to_sym)
|
427
|
-
end
|
428
|
-
nil
|
429
|
-
end
|
430
|
-
|
351
|
+
|
431
352
|
def with_inclusion_mode mode
|
432
353
|
if switch_mode = INCLUSION_MODES[ mode ] and @mode != switch_mode
|
433
354
|
old_mode, @mode = @mode, switch_mode
|
@@ -442,6 +363,8 @@ class Card
|
|
442
363
|
end
|
443
364
|
|
444
365
|
def prepare_nest opts
|
366
|
+
@char_count ||= 0
|
367
|
+
|
445
368
|
opts ||= {}
|
446
369
|
case
|
447
370
|
when opts.has_key?( :comment ) ; opts[:comment] # as in commented code
|
@@ -456,7 +379,7 @@ class Card
|
|
456
379
|
end
|
457
380
|
|
458
381
|
def expand_main opts
|
459
|
-
opts.merge!
|
382
|
+
opts.merge! root.main_opts if root.main_opts
|
460
383
|
legacy_main_opts_tweaks! opts
|
461
384
|
|
462
385
|
opts[:view] ||= :open
|