card 1.15.6 → 1.15.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 037c264a997bff49bd3d368d9458febbb5d6ece7
4
- data.tar.gz: 1afa8313419cbcf43f2e9ec169316599823d75bd
3
+ metadata.gz: a6b60af27233d8dff99d74a78a0a2af92e3d4678
4
+ data.tar.gz: 6b8cd33ddbc834023b0d61c9612440cb43a683be
5
5
  SHA512:
6
- metadata.gz: 8a40b8b9f7f1133204503eb815fec178a4f586a1e90f38782edf14e0d355c7ebb4f0d336618bb7f02773fb4e75e56682e90a00cc467f456a46dbd482212d7cc1
7
- data.tar.gz: f4e1f2c2f5ba5121248126faada05e74ec862ad98c5d27c436721b3ef030271bf49350ffc5bf579ac20dbb08028097b68a6069cb10e27f59f3b76b64fdec91ae
6
+ metadata.gz: da1d81537ed7136d0e230240b43766bc1afe5d797e4fdb1901053ac4b512985b79cd842cf2e7a51706818db00e27e35e728d240c6fa1d771ee5347a801babf8a
7
+ data.tar.gz: 0a476b7978c770089694190eb831e41d9195c2e9812ddb74fd54a7a433c43e4aa056438f7ecc8b1f6170fae42d356fdf215d5bed52c553b3410a10807b46fa38
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.15.6
1
+ 1.15.7
@@ -4,6 +4,7 @@ require_dependency File.expand_path( '../reference', __FILE__ )
4
4
 
5
5
  module Card::Chunk
6
6
  class Link < Reference
7
+ attr_reader :link_text
7
8
  word = /\s*([^\]\|]+)\s*/
8
9
  # Groups: $1, [$2]: [[$1]] or [[$1|$2]] or $3, $4: [$3][$4]
9
10
  Card::Chunk.register_class self, {
@@ -20,18 +21,18 @@ module Card::Chunk
20
21
  [ raw_syntax, nil ]
21
22
  end
22
23
  end
23
-
24
+
24
25
  @link_text = objectify @link_text
25
26
  if target =~ /\/|mailto:/
26
27
  @explicit_link = objectify target
27
28
  else
28
29
  @name = target
29
- end
30
+ end
30
31
  end
31
32
 
32
33
  def divider_index string
33
34
  #there's probably a better way to do the following. point is to find the first pipe that's not inside an inclusion
34
-
35
+
35
36
  if string.index '|'
36
37
  string_copy = "#{string}" # had to do this to create new string?!
37
38
  string.scan /\{\{[^\}]*\}\}/ do |incl|
@@ -55,7 +56,7 @@ module Card::Chunk
55
56
 
56
57
  def render_link
57
58
  @link_text = render_obj @link_text
58
-
59
+
59
60
  if @explicit_link
60
61
  @explicit_link = render_obj @explicit_link
61
62
  format.web_link @explicit_link, :text=> @link_text
@@ -80,7 +81,7 @@ module Card::Chunk
80
81
  else
81
82
  @link_text = new_name if old_name.to_name == @link_text
82
83
  end
83
-
84
+
84
85
  @text = @link_text.nil? ? "[[#{referee_name.to_s}]]" : "[[#{referee_name.to_s}|#{@link_text}]]"
85
86
  end
86
87
  end
@@ -175,38 +175,55 @@ format do
175
175
  end
176
176
  end
177
177
  end
178
+
179
+
180
+ def each_nest args={}
181
+ Card::Content.new(card.content, card).find_chunks( Card::Chunk::Reference ).each do |chunk|
182
+ yield(chunk.referee_name.to_s, nest_args(args,chunk))
183
+ end
184
+ end
185
+
186
+ def map_nests args={}, &block
187
+ result = []
188
+ each_nest args do |name, n_args|
189
+ result << block.call(name, n_args)
190
+ end
191
+ result
192
+ end
193
+
194
+ # process args for links and nests
195
+ def nest_args args, chunk=nil
196
+ r_args = item_args(args)
197
+ if @inclusion_opts
198
+ r_args.merge! @inclusion_opts.clone
199
+ end
200
+ if chunk.kind_of? Card::Chunk::Include
201
+ r_args.merge!(chunk.options)
202
+ elsif chunk.kind_of? Card::Chunk::Link
203
+ r_args.reverse_merge!(:view=>:link)
204
+ r_args.reverse_merge!(:title=>chunk.link_text) if chunk.link_text
205
+ end
206
+ r_args
207
+ end
208
+
178
209
  end
179
210
 
211
+
180
212
  format :html do
181
213
  view :tabs do |args|
182
214
  tab_buttons = ''
183
215
  tab_panes = ''
184
- Card::Content.new(card.content, card).find_chunks( Card::Chunk::Reference ).each_with_index do |item, index|
185
- active_tab = (index == 0)
186
- id = "#{card.cardname.safe_key}-#{item.referee_name.safe_key}"
187
- i_args = item_args(args)
188
- if @inclusion_opts
189
- slot_args = @inclusion_opts.clone
190
- slot_args.delete(:view)
191
- if item.kind_of? Card::Chunk::Include
192
- slot_args.merge!(item.options)
193
- end
194
- i_args.merge!(:slot=>slot_args)
195
- end
196
- url = page_path(item.referee_name, i_args)
197
- tab_name = (item.respond_to?(:options) && item.options[:title]) || item.name
216
+ active_tab = true
217
+ each_nest(:item=>:content) do |name, nest_args|
218
+ id = "#{card.cardname.safe_key}-#{name.to_name.safe_key}"
219
+ url = nest_path name, nest_args
220
+ tab_name = nest_args[:title] || name
198
221
  tab_buttons += tab_button( "##{id}", tab_name, active_tab, 'data-url'=>url.html_safe, :class=>(active_tab ? nil : 'load'))
199
- tab_content =
200
- if active_tab
201
- if item.kind_of? Card::Chunk::Include
202
- item.process_chunk { |options| prepare_nest options }
203
- else
204
- nest(Card.fetch(item, :new=>{}), i_args)
205
- end
206
- else
207
- ''
208
- end
222
+
223
+ # only render the first active tab, other tabs get loaded via ajax
224
+ tab_content = active_tab ? nest(Card.fetch(name, :new=>{}), nest_args) : ''
209
225
  tab_panes += tab_pane( id, tab_content, active_tab )
226
+ active_tab = false
210
227
  end
211
228
  tab_panel tab_buttons, tab_panes, args[:tab_type]
212
229
  end
@@ -214,6 +231,16 @@ format :html do
214
231
  args[:tab_type] ||= 'tabs'
215
232
  end
216
233
 
234
+
235
+ # create a path for a nest with respect ot the inclusion options
236
+ def nest_path name, nest_args
237
+ path_args = {}
238
+ path_args[:view] = nest_args[:view]
239
+ path_args[:slot] = nest_args.clone
240
+ path_args[:slot].delete(:view)
241
+ page_path(name, path_args)
242
+ end
243
+
217
244
  view :pills, :view=>:tabs
218
245
  def default_pills_args args
219
246
  args[:tab_type] ||= 'pills'
@@ -63,23 +63,52 @@ describe Card::Set::All::Collection do
63
63
  end
64
64
  end
65
65
 
66
+ describe '#map_nests' do
67
+ before do
68
+ Card::Auth.as_bot do
69
+ @list = Card.create! :name=>'mixed list', :content=>"[[A]]\n{{B}}\n[[C|link C]]\n{{D|name;title:nest D}}"
70
+ end
71
+ end
72
+ it 'handles links and nest arguments' do
73
+ result = @list.format.map_nests do |name,args|
74
+ [name, args]
75
+ end
76
+ expect(result).to eq [
77
+ ['A', {:view=>:closed}],
78
+ ['B', {:view=>:closed, :inc_name=>"B", :inc_syntax=>"B"}],
79
+ ['C', {:view=>:closed, :title=>'link C'}],
80
+ ['D', {:view=>"name", :title=>"nest D", :inc_name=>"D", :inc_syntax=>"D|name;title:nest D"}]
81
+ ]
82
+ end
83
+ end
84
+
66
85
  describe 'tabs view' do
67
86
  it 'renders tab panel' do
68
- tabs = render_card :tabs, :content=>"[[A]]\n[[B]]\n[C]", :type=>'pointer'
87
+ tabs = render_card :tabs, :content=>"[[A]]\n[[B]]\n[[C]]", :type=>'pointer'
69
88
  assert_view_select tabs, 'div[role=tabpanel]' do
70
89
  assert_select 'li > a[data-toggle=tab]'
71
90
  end
72
91
  end
73
92
 
74
93
  it 'loads only the first tab pane' do
75
- tabs = render_card :tabs, :content=>"[[A]]\n[[B]]\n[C]", :type=>'pointer'
94
+ tabs = render_card :tabs, :content=>"[[A]]\n[[B]]\n[[C]]", :type=>'pointer'
76
95
  assert_view_select tabs, 'div[role=tabpanel]' do
77
- assert_select 'div.tab-pane#tempo_rary-a span.card-title', 'A'
96
+ assert_select 'div.tab-pane#tempo_rary-a .card-slot#A'
78
97
  assert_select 'li > a.load[data-toggle=tab][href=#tempo_rary-b]'
79
98
  assert_select 'div.tab-pane#tempo_rary-b', ''
80
99
  end
81
100
  end
82
101
 
102
+ it 'handles relative names' do
103
+ Card::Auth.as_bot do
104
+ Card.create! :name=>'G', :content=>"[[+B]]", :type=>'pointer', :subcards=>{'+B'=>'GammaBeta'}
105
+ end
106
+ tabs = Card.fetch('G').format.render_tabs
107
+ assert_view_select tabs, 'div[role=tabpanel]' do
108
+ assert_select 'div.tab-pane#g-g-b .card-content', 'GammaBeta'
109
+ end
110
+ end
111
+
83
112
  it 'handles item views' do
84
113
  tabs = render_content '{{Fruit+*type+*create|tabs|name}}'
85
114
  assert_view_select tabs, 'div[role=tabpanel]' do
@@ -101,5 +130,13 @@ describe Card::Set::All::Collection do
101
130
  assert_select 'div.tab-pane#tab_test-a', 'Basic'
102
131
  end
103
132
  end
133
+
134
+ it 'works with search cards' do
135
+ Card.create :type=>'Search', :name=>'Asearch', :content=>%{{"type":"User"}}
136
+ tabs=render_content("{{Asearch|tabs;item:name}}")
137
+ assert_view_select tabs, 'div[role=tabpanel]' do
138
+ assert_select 'li > a[data-toggle=tab][href=#asearch-joe_admin] span.card-title', 'Joe Admin'
139
+ end
140
+ end
104
141
  end
105
142
  end
@@ -91,6 +91,21 @@ format do
91
91
  end
92
92
  end
93
93
 
94
+ def search_result_names
95
+ @search_result_names ||=
96
+ begin
97
+ card.item_names search_params
98
+ rescue => e
99
+ { :error => e}
100
+ end
101
+ end
102
+
103
+ def each_nest args={}
104
+ search_result_names.each do |name|
105
+ yield(name, nest_args(args.reverse_merge!(:item=>:content)))
106
+ end
107
+ end
108
+
94
109
  def set_inclusion_opts args
95
110
  @inclusion_defaults = nil
96
111
  @inclusion_opts ||= {}
@@ -1,7 +1,7 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
 
3
3
  describe Card::Set::Type::SearchType do
4
- it "should wrap search items with correct view class" do
4
+ it "wraps search items with correct view class" do
5
5
  Card.create :type=>'Search', :name=>'Asearch', :content=>%{{"type":"User"}}
6
6
  c=render_content("{{Asearch|core;item:name}}")
7
7
  expect(c).to match('search-result-item item-name')
@@ -10,18 +10,20 @@ describe Card::Set::Type::SearchType do
10
10
  expect(render_content("{{Asearch|core|titled}}" ).scan('search-result-item item-titled').size).to eq(14)
11
11
  end
12
12
 
13
- it "should handle returning 'count'" do
13
+ it "handles returning 'count'" do
14
14
  expect(render_card(:core, :type=>'Search', :content=>%{{ "type":"User", "return":"count"}})).to eq('14')
15
15
  end
16
-
17
- it "should pass item args correctly" do
16
+
17
+ it "passes item args correctly" do
18
18
  Card.create!(
19
- :name=>'Pointer2Searches',
20
- :type_id=>Card::PointerID,
19
+ :name=>'Pointer2Searches',
20
+ :type_id=>Card::PointerID,
21
21
  :content=>"[[Layout+*type+by name]]\n[[PlainText+*type+by name]]"
22
22
  )
23
23
  r = render_content "{{Pointer2Searches|core|closed|hide:menu}}"
24
24
  expect(r.scan('"view":"link"').size).to eq(0)
25
25
  expect(r.scan('item-closed').size).to eq(2) #there are two of each
26
26
  end
27
+
28
+ it ''
27
29
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: card
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.15.6
4
+ version: 1.15.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ethan McCutchen
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2015-06-12 00:00:00.000000000 Z
14
+ date: 2015-06-15 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: smartname