roda-papercraft 0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f4bae32ac354bba9e1ce8fe298fbfd86a2dfe61ef964c6ed3a5098554edd7371
4
+ data.tar.gz: 28683302a47e6ee38773de562150e37e003744234acfea74ec1da8c06906a9c5
5
+ SHA512:
6
+ metadata.gz: d7ab2d97ee095762649b9c5998fbefb6f6e8559318e8ece942317e565d07d45ad5f6a8d3da43864a6ee5f550d20335f7a5b509883618d169def23d62a635f343
7
+ data.tar.gz: 7a6bd908e98083b622443662197594e6f9572d0cd42f187f021ab7bc1376e63eab2e0dad37d18dafe529895669e0f9acb0ef7a93866f14922fa9493fdd8ed1a1
data/CHANGELOG.md ADDED
File without changes
data/README.md ADDED
@@ -0,0 +1,107 @@
1
+ # roda-papercraft
2
+
3
+ ## Papercraft plugin for Roda
4
+
5
+ The `roda-papercraft` Roda plugin adds some methods to let you render
6
+ [Papercraft](https://papercraft.noteflakes.com/) templates in your Roda app.
7
+ This plugin lets you either define templates inline inside your Roda router, or
8
+ load templates from files. This repository includes an example directory with an
9
+ example Roda app showing typical use.
10
+
11
+ To use Papercraft with Roda, do the following:
12
+
13
+ ### 1. Add roda-papercraft to your App
14
+
15
+ In your `Gemfile`, add the following line:
16
+
17
+ ```ruby
18
+ gem "roda-papercraft"
19
+ ```
20
+
21
+ ### 2. Activate the Papercraft Plugin
22
+
23
+ In your Roda app, load roda-papercraft:
24
+
25
+ ```ruby
26
+ require "roda-papercraft"
27
+ ```
28
+
29
+ Then load the plugin inside your app:
30
+
31
+ ```ruby
32
+ class App < Roda
33
+ plugin :papercraft
34
+ ...
35
+ end
36
+ ```
37
+
38
+ By default, the template root is `"templates"` (relative to the working
39
+ directory). To change the template root, you can configure the plugin:
40
+
41
+ ```ruby
42
+ class App < Roda
43
+ plugin :papercraft
44
+ ...
45
+ end
46
+ ```
47
+
48
+ ## Rendering Templates from Files
49
+
50
+ Your template files are normal Ruby source files. Each file should contain a
51
+ single lambda. Here's an example:
52
+
53
+ ```ruby
54
+ # templates/hello.rb
55
+ -> {
56
+ h1 "Hello from Papercraft"
57
+ }
58
+ ```
59
+
60
+ To render the template, first load it using the `#template` method, and then run
61
+ `#render` on it:
62
+
63
+ ```ruby
64
+ route do |r|
65
+ r.get "hello" do
66
+ template("hello").render
67
+ end
68
+
69
+ ...
70
+ end
71
+ ```
72
+
73
+ If the template takes arguments, you can pass them through the `#render` call:
74
+
75
+ ```ruby
76
+ # templates/greet.rb
77
+ ->(name) {
78
+ h1 "Hello, #{name}!"
79
+ }
80
+
81
+ # in your app
82
+ route do |r|
83
+ r.get "greet", String do |name|
84
+ template("greet").render(name)
85
+ end
86
+ ...
87
+ end
88
+ ```
89
+
90
+ ## Rendering Templates Inline
91
+
92
+ To render templates inline, just use `#render` directly.
93
+
94
+ ```ruby
95
+ route do |r|
96
+ r.get "hello" do
97
+ render {
98
+ h1 "Hello from Papercraft"
99
+ }
100
+ end
101
+ end
102
+ ```
103
+
104
+ ## Contributing
105
+
106
+ I gladly accept contributions to roda-papercraft. Please feel free to open
107
+ issues or PRs.
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "papercraft"
4
+ require "fileutils"
5
+
6
+ class Roda
7
+ module RodaPlugins
8
+ module Papercraft
9
+ # Set the file to load the routes metadata from. Options:
10
+ # :file :: The JSON file containing the routes metadata (default: 'routes.json')
11
+ def self.configure(app, opts = {})
12
+ template_root = opts[:template_root] || File.join(FileUtils.pwd, "templates")
13
+
14
+ app.instance_exec do
15
+ @template_root ||= template_root
16
+ end
17
+ end
18
+
19
+ module ClassMethods
20
+ def template_root
21
+ @template_root
22
+ end
23
+ end
24
+
25
+ module InstanceMethods
26
+ def render(*, **, &block)
27
+ block.render(*, **)
28
+ end
29
+
30
+ def template(name)
31
+ (@templates ||= {})[name] ||= load_template(name)
32
+ end
33
+
34
+ private
35
+
36
+ def load_template(name)
37
+ fn = File.join(self.class.template_root, "#{name}.rb")
38
+ source = IO.read(fn)
39
+ eval(source, binding, fn)
40
+ end
41
+ end
42
+ end
43
+
44
+ register_plugin(:papercraft, Papercraft)
45
+ end
46
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'roda/plugins/papercraft'
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ RODA_PAPERCRAFT_VERSION = "0.1"
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: roda-papercraft
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Sharon Rosner
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: roda
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: papercraft
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '2.17'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '2.17'
40
+ - !ruby/object:Gem::Dependency
41
+ name: minitest
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: 5.25.5
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: 5.25.5
54
+ email: sharon@noteflakes.com
55
+ executables: []
56
+ extensions: []
57
+ extra_rdoc_files:
58
+ - README.md
59
+ files:
60
+ - CHANGELOG.md
61
+ - README.md
62
+ - lib/roda-papercraft.rb
63
+ - lib/roda/plugins/papercraft.rb
64
+ - lib/roda_papercraft_version.rb
65
+ homepage: http://github.com/digital-fabric/roda-papercraft
66
+ licenses:
67
+ - MIT
68
+ metadata:
69
+ homepage_uri: https://github.com/digital-fabric/roda-papercraft
70
+ changelog_uri: https://github.com/digital-fabric/roda-papercraft/blob/master/CHANGELOG.md
71
+ rdoc_options:
72
+ - "--title"
73
+ - Roda-Papercraft
74
+ - "--main"
75
+ - README.md
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '3.4'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubygems_version: 3.7.0.dev
90
+ specification_version: 4
91
+ summary: 'roda-papercraft: Papercraft views for Roda'
92
+ test_files: []