www_app 2.1.1 → 2.1.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fc3024db22e0dd0e4ccc06caf270dced51971cbb
4
- data.tar.gz: 002d24337430dc8aff2269203bd6123c30a7944a
3
+ metadata.gz: ae67823b91ac54d165890af512d9c2b8b97fb7ea
4
+ data.tar.gz: abac21553d1cc1f37d9bc0793866075e00ffbef4
5
5
  SHA512:
6
- metadata.gz: 7b4c1487fe5a0c623a033f2074ebe4a3bdbb663fff1c64e15995f2d6082091e7bd9642db4d82afec93a0dfbe21d5c8bcfff118d25d1929e48f91776e57ec6826
7
- data.tar.gz: 2f0b7b3babf35782af496b5201ba6bb66d396822cd8c27a83e6196261eb33a34a23a925ce129ff24a73fe560a7776ebe17ceb996cebe0ad24a5555f646dfcd2a
6
+ metadata.gz: 6e5008e96ce87034649f61e66f21b7f61d06b24e8fbd980a90461694139ba86f82b1bf38d0a7107ea7100e8a176feb208f206adaf3d45d3147a2503b1defc30e
7
+ data.tar.gz: 804359ff34f1287b952f6f30587774a208fe9cd4bf955267727c9bb27d02c806093435d201f75a3be5d5c732d4c0bc647bd433bd5bd77275acae9867c547ac50
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.1.1
1
+ 2.1.3
@@ -373,10 +373,12 @@ class WWW_App
373
373
 
374
374
  @tag = new
375
375
 
376
- @tag.merge!(opts) if opts
376
+ @tag.merge!(opts) if opts.is_a?(::Hash)
377
377
 
378
378
  if block_given?
379
379
  close { yield }
380
+ elsif opts.is_a?(::String)
381
+ close { text opts }
380
382
  end
381
383
 
382
384
  self
@@ -58,8 +58,8 @@ class WWW_App
58
58
 
59
59
  TAGS.each { |name|
60
60
  eval <<-EOF, nil, __FILE__, __LINE__ + 1
61
- def #{name}
62
- create(:#{name})
61
+ def #{name} str = :none
62
+ create(:#{name}, str)
63
63
  block_given? ?
64
64
  close { yield } :
65
65
  self
@@ -87,10 +87,14 @@ class WWW_App
87
87
  create(:meta, *args)
88
88
  end
89
89
 
90
- def title
90
+ def title str = :none
91
91
  fail ":title not allowed here" if parent
92
- create :title do
93
- yield
92
+ if !block_given? && str != :none
93
+ create { text str }
94
+ else
95
+ create :title do
96
+ yield
97
+ end
94
98
  end
95
99
  end
96
100
 
@@ -203,6 +203,9 @@ class WWW_App
203
203
  when t_name == :style
204
204
  style_tags[:children] << t
205
205
 
206
+ when t_name == :link
207
+ head[:children] << t
208
+
206
209
  when t_name == :_ && !parent
207
210
  body[:css] = (body[:css] || {}).merge(t[:css]) if t[:css]
208
211
  body[:class] = (body[:class] || []).concat(t[:class]) if t[:class]
@@ -382,6 +385,10 @@ class WWW_App
382
385
  Clean.html(tag[:value])
383
386
  )
384
387
 
388
+ when t_name == :link
389
+ final << (
390
+ %^#{SPACES(indent)}<link type="text/css" rel="stylesheet" href="#{::Escape_Escape_Escape.relative_href tag[:href]}" />^
391
+ )
385
392
 
386
393
  when t_name == :meta
387
394
  case
@@ -394,7 +401,7 @@ class WWW_App
394
401
  end
395
402
 
396
403
  final << (
397
- %^#{SPACES(indent)}<meta #{key_name}="#{key_content}" content="#{content}" />^
404
+ %^#{SPACES(indent)}<meta #{key_name}="#{key_content}" content="#{content}" />\n^
398
405
  )
399
406
 
400
407
  when t_name == :html # === :html tag ================
@@ -476,17 +483,19 @@ class WWW_App
476
483
  ]
477
484
  }
478
485
 
479
- clean_vals = stacks[:js].map { |raw_x| stacks[:clean_text].call(raw_x) }
480
- content = <<-EOF
481
- \n#{SPACES(indent)}WWW_App.run( #{::Escape_Escape_Escape.json_encode(clean_vals)} );
482
- EOF
486
+ if !stacks[:js].empty?
487
+ clean_vals = stacks[:js].map { |raw_x| stacks[:clean_text].call(raw_x) }
488
+ content = <<-EOF
489
+ \n#{SPACES(indent)}WWW_App.run( #{::Escape_Escape_Escape.json_encode(code: clean_vals)} );
490
+ EOF
483
491
 
484
- new_todo.concat [
485
- :clean_attrs, {:type=>'application/javascript'}, script_tag,
486
- :open, :script,
487
- {:tag_name=>:text, :skip_escape=>true, :value=> content },
488
- :close, :script
489
- ]
492
+ new_todo.concat [
493
+ :clean_attrs, {:type=>'application/javascript'}, script_tag,
494
+ :open, :script,
495
+ {:tag_name=>:text, :skip_escape=>true, :value=> content },
496
+ :close, :script
497
+ ]
498
+ end
490
499
 
491
500
  todo = new_todo.concat(todo)
492
501
 
@@ -30,7 +30,7 @@ def strip_each_line str
30
30
  end
31
31
 
32
32
  def get_content tag, html
33
- ( html.match(/\<#{tag}\>(.+)\<\/#{tag}\>/)[1] || '' ).
33
+ ( html.match(/\<#{tag}\>(.+)\<\/#{tag}\>/m)[1] || '' ).
34
34
  split("\n").
35
35
  map(&:strip).
36
36
  join "\n"
@@ -10,17 +10,29 @@ describe :link do
10
10
  end
11
11
 
12
12
  it "escapes slashes in :href" do
13
- target %^<link href="&#47;css&#47;css&#47;styles.css" />^
14
- actual {
13
+ target = %^<link type="text/css" rel="stylesheet" href="&#47;css&#47;css&#47;styles.css" />^
14
+ WWW_App.new {
15
15
  link.href('/css/css/styles.css')./
16
- }
16
+ }.to_html.scan(target).should == [target]
17
17
  end
18
18
 
19
+ it "gets rendered in :head" do
20
+ html = get_content(:head, WWW_App.new {
21
+ link.type('text/css').rel('stylesheet').href("/file.css")./
22
+ }.to_html)
23
+
24
+ html.
25
+ scan(%r!<link [^>]+>!).
26
+ should == [<<-EOF.strip]
27
+ <link type="text/css" rel="stylesheet" href="&#47;file.css" />
28
+ EOF
29
+ end # === it gets rendered in :head
30
+
19
31
  it "allows a relative :href" do
20
- target %^<link href="&#47;css.css" />^
21
- actual {
32
+ target = %^<link type="text/css" rel="stylesheet" href="&#47;css.css" />^
33
+ WWW_App.new {
22
34
  link.href('/css.css')./
23
- }
35
+ }.to_html.scan(target).should == [target]
24
36
  end
25
37
 
26
38
  end # === describe :link
@@ -10,6 +10,13 @@ describe :text do
10
10
  end
11
11
  end # === it prints a string if value is a hash: {:type=>:string, ...}
12
12
 
13
+ it "prints a string passed to it as a single argument" do
14
+ target :body, %^<p>string string</p>^
15
+ actual do
16
+ p "string string"
17
+ end
18
+ end # === it prints a string passed to it as a single argument
19
+
13
20
  end # === describe "string content"
14
21
 
15
22
  describe :raw_text do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: www_app
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - da99
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-23 00:00:00.000000000 Z
11
+ date: 2015-03-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yajl-ruby