papercraft 0.22 → 0.23

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
  SHA256:
3
- metadata.gz: 729c7b1cf7482cb761b005fba8da8ae4c1325559daee15fedd2d695de21ee08d
4
- data.tar.gz: 0546c527a6a9ac0570c9bd6057101b31591eba1f1ee549c272d9bda13a9f7a04
3
+ metadata.gz: 341520b9db20c53da441299fb449c4eea3321924517f4b93e70af1119b4516c3
4
+ data.tar.gz: 861a5a2747c3a468abb780cf50710698e52fbac1fc236c8672c2bbb328db6f4d
5
5
  SHA512:
6
- metadata.gz: fdaa8d2f254744694ea3624f39871f4b411294a990f6e1bb4c57f56bf36049031b9403820cbadaa57ef6ac3e9021b6afa53da22588462450a6ca0863b6b88184
7
- data.tar.gz: 4ea21235970af0cdef9ce09cd790742a94632e4f1f02d4a3d90a3e857741ec41952a53fe59b24016c00894dde7131dbbbc79d7616564f159f5646acf24f469f9
6
+ metadata.gz: 7668a984a2c7957ba3f65234eab6770b4e969e0d2b4e1345839db8c0711d07afbfef5735b67de9a94c22994b4b6c1d6b2f87e07a810a0cae04ccbecb1ff5b38f
7
+ data.tar.gz: 1605f9b1459ab20b9cec97805529764ece6058ce34609dc7d75fe38d8b35889c65e4afa5174f1c1d89dfb46205d282e65e1020995c999f66b84a5f9b5e505de1
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.23 2022-02-15
2
+
3
+ - Remove unused `Encoding` module
4
+ - Add SOAP extension (#11, thanks [@aemadrid](https://github.com/aemadrid))
5
+
1
6
  ## 0.22 2022-02-14
2
7
 
3
8
  - Fix behaviour of call to `#p` in an extension (#10)
data/README.md CHANGED
@@ -78,9 +78,10 @@ hello.render('world')
78
78
  - [Emitting Markdown](#emitting-markdown)
79
79
  - [Working with MIME types](#working-with-mime-types)
80
80
  - [Deferred evaluation](#deferred-evaluation)
81
- - [Papercraft extensions](#papercraft-extensions)
82
81
  - [XML templates](#xml-templates)
83
82
  - [JSON templates](#json-templates)
83
+ - [Papercraft extensions](#papercraft-extensions)
84
+ - [Bundled extensions](#bundled-extensions)
84
85
  - [API Reference](#api-reference)
85
86
 
86
87
  ## Installing Papercraft
@@ -521,6 +522,72 @@ page = default_layout.apply {
521
522
  }
522
523
  ```
523
524
 
525
+ ## XML templates
526
+
527
+ XML templates behave largely the same as HTML templates, with a few minor
528
+ differences. XML templates employ a different encoding algorithm, and lack some
529
+ specific HTML functionality, such as emitting Markdown.
530
+
531
+ Here's an example showing how to create an RSS feed:
532
+
533
+ ```ruby
534
+ rss = Papercraft.xml(mime_type: 'text/xml; charset=utf-8') { |resource:, **props|
535
+ rss(version: '2.0', 'xmlns:atom' => 'http://www.w3.org/2005/Atom') {
536
+ channel {
537
+ title 'Noteflakes'
538
+ link 'https://noteflakes.com/'
539
+ description 'A website by Sharon Rosner'
540
+ language 'en-us'
541
+ pubDate Time.now.httpdate
542
+ emit '<atom:link href="https://noteflakes.com/feeds/rss" rel="self" type="application/rss+xml" />'
543
+
544
+ article_entries = resource.page_list('/articles').reverse
545
+
546
+ article_entries.each { |e|
547
+ item {
548
+ title e[:title]
549
+ link "https://noteflakes.com#{e[:url]}"
550
+ guid "https://noteflakes.com#{e[:url]}"
551
+ pubDate e[:date].to_time.httpdate
552
+ description e[:html_content]
553
+ }
554
+ }
555
+ }
556
+ }
557
+ }
558
+ ```
559
+
560
+ ## JSON templates
561
+
562
+ JSON templates behave largely the same as HTML and XML templates. The only major
563
+ difference is that for adding array items you'll need to use the `#item` method:
564
+
565
+ ```ruby
566
+ Papercraft.json {
567
+ item 1
568
+ item 2
569
+ item 3
570
+ }.render #=> "[1,2,3]"
571
+ ```
572
+
573
+ Otherwise, you can create arbitrarily complex JSON structures by mixing hashes
574
+ and arrays:
575
+
576
+ ```Ruby
577
+ Papercraft.json {
578
+ foo {
579
+ bar {
580
+ item nil
581
+ item true
582
+ item 123.456
583
+ }
584
+ }
585
+ }.render #=> "{\"foo\":{\"bar\":[null,true,123.456]}}"
586
+ ```
587
+
588
+ Papercraft uses the [JSON gem](https://rubyapi.org/3.1/o/json) under the hood in
589
+ order to generate actual JSON.
590
+
524
591
  ## Papercraft extensions
525
592
 
526
593
  Papercraft extensions are modules that contain one or more methods that can be
@@ -593,72 +660,56 @@ Papercraft.html {
593
660
  }
594
661
  ```
595
662
 
596
- ## XML templates
663
+ ## Bundled Extensions
597
664
 
598
- XML templates behave largely the same as HTML templates, with a few minor
599
- differences. XML templates employ a different encoding algorithm, and lack some
600
- specific HTML functionality, such as emitting Markdown.
665
+ Papercraft comes bundled with a few extensions that address common use cases.
666
+ All bundled extensions are namespaced under `Papercraft::Extensions`, and must
667
+ be specifically required in order to be available to templates.
601
668
 
602
- Here's an example showing how to create an RSS feed:
669
+ For all bundled Papercraft extensions, there's no need to call
670
+ `Papercraft.extension`, requiring the extension is sufficient.
603
671
 
604
- ```ruby
605
- rss = Papercraft.xml(mime_type: 'text/xml; charset=utf-8') { |resource:, **props|
606
- rss(version: '2.0', 'xmlns:atom' => 'http://www.w3.org/2005/Atom') {
607
- channel {
608
- title 'Noteflakes'
609
- link 'https://noteflakes.com/'
610
- description 'A website by Sharon Rosner'
611
- language 'en-us'
612
- pubDate Time.now.httpdate
613
- emit '<atom:link href="https://noteflakes.com/feeds/rss" rel="self" type="application/rss+xml" />'
614
-
615
- article_entries = resource.page_list('/articles').reverse
672
+ ### SOAP extension
616
673
 
617
- article_entries.each { |e|
618
- item {
619
- title e[:title]
620
- link "https://noteflakes.com#{e[:url]}"
621
- guid "https://noteflakes.com#{e[:url]}"
622
- pubDate e[:date].to_time.httpdate
623
- description e[:html_content]
624
- }
625
- }
626
- }
627
- }
628
- }
629
- ```
674
+ > The SOAP extension was contributed by [@aemadrid](https://github.com/aemadrid).
630
675
 
631
- ## JSON templates
676
+ The SOAP extension provides common tags for building SOAP payloads. To load the
677
+ SOAP extensions, require `polyphony/extensions/soap`. The extension provides the
678
+ following methods:
632
679
 
633
- JSON templates behave largely the same as HTML and XML templates. The only major
634
- difference is that for adding array items you'll need to use the `#item` method:
680
+ - `soap.Body(...)` - emits a `soap:Body` tag.
681
+ - `soap.Envelope(...)` - emits a `soap:Envelope` tag.
682
+ - `soap.Fault(...)` - emits a `soap:Fault` tag.
683
+ - `soap.Header(...)` - emits a `soap:Header` tag.
635
684
 
636
- ```ruby
637
- Papercraft.json {
638
- item 1
639
- item 2
640
- item 3
641
- }.render #=> "[1,2,3]"
642
- ```
685
+ As mentioned above, namespaced tags and attributes may be specified by using
686
+ double underscores for colons. Other tags that contain special characters may be
687
+ emitted using the `#tag` method:
643
688
 
644
- Otherwise, you can create arbitrarily complex JSON structures by mixing hashes
645
- and arrays:
689
+ ```ruby
690
+ require 'polyphony/extensions/soap'
646
691
 
647
- ```Ruby
648
- Papercraft.json {
649
- foo {
650
- bar {
651
- item nil
652
- item true
653
- item 123.456
692
+ xml = Papercraft.xml {
693
+ soap.Envelope(
694
+ xmlns__xsd: 'http://www.w3.org/2001/XMLSchema',
695
+ xmlns__xsi: 'http://www.w3.org/2001/XMLSchema-instance'
696
+ ) {
697
+ soap.Body {
698
+ PosRequest(xmlns: 'http://Some.Site') {
699
+ tag('Ver1.0') {
700
+ Header {
701
+ SecretAPIKey 'some_secret_key'
702
+ }
703
+ Transaction {
704
+ SomeData {}
705
+ }
706
+ }
707
+ }
654
708
  }
655
709
  }
656
- }.render #=> "{\"foo\":{\"bar\":[null,true,123.456]}}"
710
+ }
657
711
  ```
658
712
 
659
- Papercraft uses the [JSON gem](https://rubyapi.org/3.1/o/json) under the hood in
660
- order to generate actual JSON.
661
-
662
713
  ## API Reference
663
714
 
664
715
  The API reference for this library can be found
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Papercraft
4
+ module Extensions
5
+ module Soap
6
+ # Emits a SOAP XML tag that identifies the XML document as a SOAP message.
7
+ #
8
+ # @param **props [Hash] tag attributes
9
+ # @param &block [Proc] optional inner XML
10
+ # @return [void]
11
+ def Envelope(**props, &block)
12
+ props[:xmlns__soap] ||= 'http://schemas.xmlsoap.org/soap/envelope/'
13
+ tag('soap:Envelope', **props, &block)
14
+ end
15
+
16
+ # Emits a SOAP XML tag that contains header information.
17
+ #
18
+ # @param **props [Hash] tag attributes
19
+ # @param &block [Proc] optional inner XML
20
+ # @return [void]
21
+ def Header(**props, &blk)
22
+ tag('soap:Header', **props, &blk)
23
+ end
24
+
25
+ # Emits a SOAP XML tag that contains header information.
26
+ #
27
+ # @param **props [Hash] tag attributes
28
+ # @param &block [Proc] optional inner XML
29
+ # @return [void]
30
+ def Body(**props, &blk)
31
+ tag('soap:Body', **props, &blk)
32
+ end
33
+
34
+ # Emits a SOAP XML tag that contains errors and status information.
35
+ #
36
+ # @param **props [Hash] tag attributes
37
+ # @param &block [Proc] optional inner XML
38
+ # @return [void]
39
+ def Fault(**props, &blk)
40
+ tag('soap:Fault', **props, &blk)
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+ Papercraft.extension(soap: Papercraft::Extensions::Soap)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Papercraft
4
- VERSION = '0.22'
4
+ VERSION = '0.23'
5
5
  end
data/lib/papercraft.rb CHANGED
@@ -6,7 +6,6 @@ require 'kramdown-parser-gfm'
6
6
 
7
7
  require_relative 'papercraft/template'
8
8
  require_relative 'papercraft/renderer'
9
- require_relative 'papercraft/encoding'
10
9
  # require_relative 'papercraft/compiler'
11
10
 
12
11
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: papercraft
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.22'
4
+ version: '0.23'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sharon Rosner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-14 00:00:00.000000000 Z
11
+ date: 2022-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: escape_utils
@@ -134,8 +134,8 @@ files:
134
134
  - README.md
135
135
  - lib/papercraft.rb
136
136
  - lib/papercraft/compiler.rb
137
- - lib/papercraft/encoding.rb
138
137
  - lib/papercraft/extension_proxy.rb
138
+ - lib/papercraft/extensions/soap.rb
139
139
  - lib/papercraft/html.rb
140
140
  - lib/papercraft/json.rb
141
141
  - lib/papercraft/renderer.rb
@@ -1,26 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Papercraft
4
- # Papercraft::Encoding includes common encoding methods
5
- module Encoding
6
- # Encodes the given string to safe HTML text, converting special characters
7
- # into the respective HTML entities. If a non-string value is given, it is
8
- # converted to `String` using `#to_s`.
9
- #
10
- # @param text [String] string to be encoded
11
- # @return [String] HTML-encoded string
12
- def __html_encode__(text)
13
- EscapeUtils.escape_html(text.to_s)
14
- end
15
-
16
- # Encodes the given string to safe URI component, converting special
17
- # characters to URI entities. If a non-string value is given, it is
18
- # converted to `String` using `#to_s`.
19
- #
20
- # @param text [String] string to be encoded
21
- # @return [String] URI-encoded string
22
- def __uri_encode__(text)
23
- EscapeUtils.escape_uri(text.to_s)
24
- end
25
- end
26
- end