mkmatter 3.0.26

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
+ SHA1:
3
+ metadata.gz: 5820176bd7d2e83b046fea9d79bf535e7c8090a4
4
+ data.tar.gz: b4a73fb3ccea1a7569253138b407260e45a14dd5
5
+ SHA512:
6
+ metadata.gz: 88a64684f76531d7c27c11f40222aa5d7e3a08f845ccf7d7261b3e874000c9d662f10f41d81b38da0018a55f31cc700103e72251a5caf4e273701bffff1afd2b
7
+ data.tar.gz: 9c1a898a666ab077ea9ffa6affb1442819ff31ae7faab37d7ea4edfa76b5849c3211d7373c20ff5529b4c1c300d7c699c1f3abff3c437b07267966bcfb94eb57
@@ -0,0 +1,7 @@
1
+ ## Debug Table
2
+
3
+ <!-- Run mkmatter --debug and paste it in between the <pre> tags-->
4
+
5
+ <pre>
6
+
7
+ </pre>
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /.idea/
10
+ /.vscode/
11
+ /vendor/
12
+ Gemfile.lock
13
+ *.gem
14
+ pkg/
data/.gitlab-ci.yml ADDED
@@ -0,0 +1,24 @@
1
+ image: ruby:2.3
2
+
3
+ cache:
4
+ paths:
5
+ - vendor/
6
+
7
+ before_script:
8
+ - export LC_ALL="C.UTF-8"
9
+ - export LANG="en_US.UTF-8"
10
+ - export LANGUAGE="en_US.UTF-8"
11
+
12
+ build:
13
+ stage: build
14
+ script:
15
+ - bundle install --path vendor/bundle
16
+ only:
17
+ - master
18
+ - tags
19
+
20
+ test:
21
+ stage: test
22
+ script:
23
+ - bundle install --path vendor/bundle
24
+ - rake spec
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.2
5
+ - 2.3.0
6
+ - 2.4.0
7
+ - 2.5.0
8
+ script:
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mkmatter.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Ken Spencer
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Ken Spencer
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,99 @@
1
+ # mkmatter
2
+
3
+ ###### Builds & Links
4
+ [![Travis branch](https://img.shields.io/travis/IotaSpencer/mkmatter/dev.svg?style=for-the-badge)](https://travis-ci.org/IotaSpencer/mkmatter)
5
+ [![Travis branch](https://img.shields.io/travis/IotaSpencer/mkmatter/master.svg?style=for-the-badge)](https://travis-ci.org/IotaSpencer/mkmatter)
6
+
7
+ [![Gem](https://img.shields.io/gem/v/mkmatter.svg?style=for-the-badge)](https://rubygems.org/gems/mkmatter)
8
+ [![GitHub tag](https://img.shields.io/github/tag/IotaSpencer/mkmatter.svg?style=for-the-badge)](https://github.com/IotaSpencer/mkmatter/tree/v3.0.1)
9
+
10
+ [![Gem](https://img.shields.io/gem/dt/mkmatter.svg?style=for-the-badge)](https://rubygems.org/gems/mkmatter)
11
+ [![Gem](https://img.shields.io/gem/dtv/mkmatter.svg?style=for-the-badge)](https://rubygems.org/gems/mkmatter)
12
+ [![Gem](https://img.shields.io/gem/dv/mkmatter/3.0.25.svg?style=for-the-badge)](https://github.com/IotaSpencer/mkmatter/tree/v3.0.1)
13
+
14
+ ###### Badges
15
+
16
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=for-the-badge)](https://opensource.org/licenses/MIT)
17
+ [![forthebadge](https://forthebadge.com/images/badges/uses-badges.svg)](https://forthebadge.com)
18
+ [![forthebadge](https://forthebadge.com/images/badges/built-with-love.svg)](https://forthebadge.com)
19
+ [![forthebadge](https://forthebadge.com/images/badges/uses-git.svg)](https://forthebadge.com)
20
+
21
+
22
+
23
+ ## Contact
24
+
25
+ [![E-mail](https://img.shields.io/badge/Email-Me-green.svg?style=for-the-badge)](mailto:me@iotaspencer.me)
26
+ [![Website](https://img.shields.io/website-up-down-green-red/https/iotaspencer.me.svg?label=My%20Site%20-%20IotaSpencer%2Eme&style=for-the-badge)](https://iotaspencer.me)
27
+ [![E-mail](https://img.shields.io/badge/mkmatter%20on%20IotaSpencer%2eme-Project-green.svg?style=for-the-badge)](https://iotaspencer.me/projects/mkmatter)
28
+ [![Twitter Follow](https://img.shields.io/twitter/follow/IotaEcode.svg?label=Follow%20Me%20on%20Twitter&style=for-the-badge)](https://twitter.com/IotaEcode)
29
+
30
+ ## About mkmatter
31
+
32
+ 'mkmatter' is a gem designed to make it easy to generate front matter for files and also subsequently edit them.
33
+
34
+ **Note**: Just like Jekyll there are minimal constraints on what is needed to build, but for `mkmatter` all I ask is that there is a `_config.yml` in your site source root, so the executable knows where it is in the filesystem.
35
+
36
+ This is needed for any part that `reads from/writes to` the filesystem.
37
+
38
+ ## Installation
39
+
40
+ Add this line to your application's Gemfile:
41
+
42
+ ```ruby
43
+ gem 'mkmatter'
44
+ ```
45
+
46
+ And then execute:
47
+
48
+ $ bundle install
49
+
50
+ ### Standalone
51
+
52
+ To install to the system/user instead of a project, use the following
53
+
54
+ #### System-wide
55
+ As root or by using sudo, run:
56
+
57
+ ```$ gem install mkmatter```
58
+
59
+ or
60
+
61
+ ```$ sudo gem install mkmatter```
62
+
63
+ #### User
64
+
65
+ ```$ gem install --user-install mkmatter```
66
+
67
+ ## Usage
68
+
69
+ ### Using 'mkmatter'
70
+
71
+ If you want to use 'mkmatter', an executable that ships with `mkmatter`, you gots to run it
72
+
73
+ **Note**: Due to minimal constraints in Jekyll, I require at least an empty `_config.yml` file at the root of your source directory.
74
+
75
+ **P.S.**: **It does not have to have any directives, it can be an empty file.**
76
+
77
+ #### Command 'new'
78
+
79
+ 1. 'new' is for generating front matter and content
80
+
81
+ 1. The current commands under 'new' are 'post' and 'page'
82
+
83
+ Which will ask you questions about the content you want to put out.
84
+ * The script also will open an editor (the 'editor' command) if allowed to, as to allow the user to begin editing their file, front-matter already included.
85
+
86
+ ## Contributing
87
+
88
+ * I am open to the idea of adding more questions/modules if there are plugins that require more configuration in the front matter. Just let me know!
89
+
90
+ * [Bug Reports](https://github.com/IotaSpencer/mkmatter/issues)
91
+ * [Pull Requests](https://github.com/IotaSpencer/mkmatter/pulls)
92
+
93
+ <!--
94
+ **Tutorial**: [mkmatter Tutorial on IotaSpencer.me](https://iotaspencer.me/2018-02-XX-mkmatter-tutorial)
95
+ -->
96
+
97
+ ## License
98
+
99
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new('spec')
5
+
6
+
7
+ desc 'Run tests'
8
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'mkmatter'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ #require 'irb'
14
+ #IRB.start(__FILE__)
15
+ require 'pry'
16
+ Pry.start
data/bin/mkmatter ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/ruby
2
+ require 'mkmatter'
3
+
4
+
5
+ Signal.trap('INT') do
6
+ $stderr.puts
7
+ $stderr.puts 'Got INT.. Exiting'
8
+ exit 0
9
+ end
10
+ Mkmatter::App::Runner.new(ARGV.dup).execute!
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,79 @@
1
+ require 'yaml'
2
+ require 'active_support/all'
3
+ require 'highline'
4
+ module Mkmatter
5
+ class Answers
6
+ attr_accessor :title, :tags, :categories
7
+ attr_accessor :date, :layout, :draft
8
+ attr_accessor :slug_date, :answer_hash
9
+ attr_accessor :published, :file_format
10
+ attr_reader :matter
11
+
12
+ def initialize(question_hash, publish)
13
+
14
+ @layout = question_hash[:layout]
15
+ @title = question_hash[:title]
16
+ @tags = question_hash[:tags]
17
+ @categories = question_hash[:categories]
18
+ Time.zone = question_hash[:time_zone]
19
+ now = Time.zone.now
20
+ @date = now.to_s
21
+ @slug_date = now.strftime('%Y-%m-%d')
22
+ @published = publish
23
+ @file_format = question_hash[:file_format]
24
+ @keywords = question_hash[:keywords]
25
+ @description = question_hash[:description]
26
+ @matter = {
27
+ layout: @layout,
28
+ title: @title,
29
+ categories: @categories,
30
+ tags: @tags,
31
+ date: @date,
32
+ }
33
+ @matter[:published] = @published if publish
34
+ end
35
+
36
+ # @return [Hash] returns attribute `.matter`
37
+ def to_h
38
+ @matter
39
+ end
40
+
41
+ # @param [Hash] hash other hash
42
+ # @return [nil] merges hash into attribute `.matter`
43
+ def to_h=(hash)
44
+ @matter.merge!(hash)
45
+ end
46
+
47
+ alias_method :inspect, :to_h
48
+ #
49
+ # Dumps all file applicable metadata to a provided output.
50
+ # @param [Boolean] to_file A path or filename
51
+ # @param [Boolean] stdout Whether to print to stdout
52
+ def dump
53
+ custom_fields = nil
54
+ hl = HighLine.new($stdin, $stderr, 80)
55
+ # Custom matter
56
+ if hl.agree('Do you want to add custom fields? (usable as {{LAYOUT_TYPE.FIELD}} in templates) ', true)
57
+ hl.say('Your fields should be inputted as FIELD=>TEXT HERE')
58
+ hl.say("Enter 'EOL' on a new line and press enter when you are done.")
59
+ hl.say("<% HighLine.color('NOTE', :bold, :red) %>: Input is <% HighLine.color('NOT', :bold, :red) %> evaluated!")
60
+ custom_fields = hl.ask('Fields?') do |q|
61
+ q.gather = /^EOL$/
62
+ end
63
+ end
64
+ if custom_fields
65
+ fields = Hash.new
66
+ custom_fields.each do |field|
67
+ field = field.split(/=>/)
68
+ fields.store(field[0].to_s, field[1])
69
+ end
70
+ self.to_h = fields
71
+ elsif custom_fields.nil?
72
+ hl.say('No extra fields were added.')
73
+ else
74
+ end
75
+ self.to_h.stringify_keys.to_yaml(indentation: 2)
76
+ '---'
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,102 @@
1
+ require 'thor'
2
+ require 'highline'
3
+ require 'slugity/extend_string'
4
+ require 'yaml'
5
+ require 'active_support/all'
6
+ require 'terminal-table'
7
+ require 'os'
8
+ require 'rbconfig'
9
+
10
+ require 'mkmatter'
11
+ require 'mkmatter/cli/subs'
12
+ module Mkmatter
13
+ module App
14
+ class CLI < Thor
15
+ include Thor::Actions
16
+ HILINE = HighLine.new($stdin, $stderr, 80)
17
+ map %w[--version -v] => :__print_version
18
+ desc '--version, -v', 'Print the version'
19
+
20
+ # Prints version string
21
+ def __print_version
22
+ puts Mkmatter::VERSION
23
+ end
24
+
25
+ map %w[--debug -d] => :__debug
26
+ desc '--debug, -d', 'Prints debug info about the script/gem'
27
+ # Prints debug info
28
+ def __debug
29
+ info = Mkmatter::GemInfo.new
30
+ report = YAML.safe_load(OS.report)
31
+ rows = {
32
+ 'mkmatter_version' => Mkmatter::VERSION,
33
+ 'ruby_version' => RbConfig::CONFIG['RUBY_PROGRAM_VERSION'],
34
+ }
35
+ rows.merge! report
36
+ rows.merge!({
37
+ 'ruby_bin' => OS.ruby_bin,
38
+ 'windows' => OS.windows?,
39
+ 'posix' => OS.posix?,
40
+ 'mac' => OS.mac?,
41
+ 'under windows' => OS::Underlying.windows?,
42
+ 'under bsd' => OS::Underlying.bsd?
43
+ })
44
+ table = Terminal::Table.new
45
+ table.style.width = 80
46
+ table.style.border_top = false
47
+ table.title = 'mkmatter Debug Info'
48
+ table.rows = rows.to_a
49
+ table.align_column(0, :left)
50
+ width = table.style.width - 2
51
+ print '+', '-' * width, '+'
52
+ puts
53
+ puts table
54
+ puts
55
+ end
56
+
57
+ map %w[--info -i] => :__print_info
58
+ desc '--info, -i', 'Print script/gem info'
59
+ method_option :'info-format', :type => :string, desc: 'The format of info', enum: %w(table yaml), default: 'table'
60
+ def __print_info
61
+ format = options[:'info-format']
62
+ rows = {
63
+ 'Author(s)': Mkmatter::GemInfo.authors,
64
+ 'E-Mail': Mkmatter::GemInfo.email,
65
+ 'mkmatter-Version': Mkmatter::VERSION,
66
+ 'RubyGems-Version': RbConfig::CONFIG['RUBY_PROGRAM_VERSION'],
67
+ 'Platform': RbConfig::CONFIG['build_os']
68
+ }
69
+ case format
70
+ when 'table'
71
+ table = Terminal::Table.new
72
+ table.style.width = 60
73
+ table.style.border_top = false
74
+ table.style.alignment = :center
75
+ table.title = 'mkmatter Info'
76
+ table.rows = rows.to_a
77
+ table.align_column(0, :left)
78
+ width = table.style.width - 2
79
+ print '+', '-' * width, '+'
80
+ puts
81
+ puts table
82
+ puts
83
+ when 'yaml'
84
+ puts rows.stringify_keys.to_yaml
85
+
86
+ else
87
+ # noop
88
+ # this doesn't get run because of
89
+ # the logic of options and their
90
+ # enum parameter.
91
+ end
92
+ end
93
+
94
+ desc 'new SUBCOMMAND [options]', 'Make new content'
95
+ subcommand 'new', Mkmatter::App::Classes::NewContent
96
+ desc 'tags SUBCOMMAND [options]', 'Generate or Create tags'
97
+ subcommand 'tags', Mkmatter::App::Classes::Tags
98
+ end
99
+
100
+
101
+ end
102
+ end
@@ -0,0 +1,44 @@
1
+ require 'highline'
2
+ HighLine.colorize_strings
3
+
4
+ module Mkmatter
5
+ module App
6
+ module Descriptions
7
+ module New
8
+ PAGE = <<-PAGEDOC
9
+ `mkmatter new page` will run you through making a jekyll page.
10
+
11
+ Given the above options/flags you can modify how the script
12
+
13
+ outputs your front matter, or whether to mark it as published.
14
+
15
+ PAGEDOC
16
+
17
+ POST = <<-POSTDOC
18
+ `mkmatter new post` will run you through making a jekyll post.
19
+
20
+ Given the above options/flags you can modify how the script
21
+
22
+ outputs your front matter, and whether to mark it as published,
23
+
24
+ or as a draft and move it into `_drafts`.
25
+
26
+ NOTES:
27
+
28
+
29
+ By default Jekyll will publish a post if `published` is omitted in
30
+
31
+ the front matter. So if you omit `--publish` you will publish,
32
+
33
+ so you have to explicitly use --no-publish to set `#{HighLine.color('published', :yellow)}: #{HighLine.color('false', :yellow, :bold)}`
34
+
35
+ POSTDOC
36
+ end
37
+ module Tags
38
+ GEN = <<-GENDOC
39
+
40
+ GENDOC
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,82 @@
1
+ require 'highline'
2
+ require 'find'
3
+ require 'yaml'
4
+ module Mkmatter
5
+ class Methods
6
+ def Methods.check_if_jekyll
7
+ cwd = Pathname.new('.')
8
+ cwd.ascend do |path|
9
+ if path.join('_config.yml').exist?
10
+ break true
11
+ elsif cwd.to_s == '/'
12
+ # hit root, stop
13
+ break false
14
+ end
15
+ end
16
+ end
17
+
18
+ def Methods.get_jekyll_root
19
+ if Methods.check_if_jekyll
20
+ cwd = Pathname.new('.').realdirpath
21
+ cwd.ascend do |path|
22
+ if path.join('_config.yml').exist?
23
+ return path
24
+ else
25
+ next
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ def Methods.launch_editor(file_path)
32
+ hl = HighLine.new($stdin, $stderr, 80)
33
+ if file_path
34
+ if hl.agree("Would you like to open an editor? ('editor' command) ", true)
35
+ pid = spawn("editor #{file_path}")
36
+ Process.wait pid
37
+ end
38
+ end
39
+ end
40
+
41
+
42
+ def Methods.find_front_matter(type, key)
43
+ unless type =~ /^(post|page)$/
44
+ $stderr.puts "#{HighLine.color('Error', :red, :bold)}: Invalid Argument, allowed values: post, page"
45
+ exit 1
46
+ end
47
+ yaml_loader = ->(string) {YAML.load(string)}
48
+ files = {}
49
+ html_front_matter = []
50
+ md_front_matter = []
51
+ front_matter = {}
52
+ case type
53
+ when 'page'
54
+ Find.find(Methods.get_jekyll_root.to_s) do |path|
55
+ Find.prune if path =~ /(_includes|_layouts|_docs|_site)/ # don't include layouts, includes, site, docs
56
+ Find.prune if path =~ /(_posts)/ # don't include our own posts either
57
+ Find.prune if path =~ /(vendor\/bundle)/ # don't include vendor/
58
+ Find.prune if path =~ /(\/tag\/)/ # don't include our own tags
59
+ html_front_matter << path if path =~ /.*\.html$/
60
+ md_front_matter << path if path =~ /.*\.md$/
61
+ end
62
+
63
+ when 'post'
64
+ Find.find(Pathname(Methods.get_jekyll_root).join('_posts').to_path) do |path|
65
+ html_front_matter << path if path =~ /.*\.html$/
66
+ md_front_matter << path if path =~ /.*\.md$/
67
+ end
68
+ else
69
+ # noop
70
+ end
71
+ files['html'] = html_front_matter
72
+ files['md'] = md_front_matter
73
+ files.each do |ftype, array|
74
+ array.each do |ele|
75
+ front_matter[ele] = YAML.load_file(ele)[key]
76
+ end
77
+ end
78
+ front_matter.select! {|k, v| !v.nil?}
79
+ front_matter
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,51 @@
1
+ require 'mkmatter/cli/app'
2
+
3
+ module Mkmatter
4
+ module App
5
+ class Runner
6
+ # Allow everything fun to be injected from the outside while defaulting to normal implementations.
7
+ def initialize(argv, stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = Kernel)
8
+ @argv, @stdin, @stdout, @stderr, @kernel = argv, stdin, stdout, stderr, kernel
9
+ end
10
+
11
+ def execute!
12
+ exit_code = begin
13
+ # Thor accesses these streams directly rather than letting them be injected, so we replace them...
14
+ $stderr = @stderr
15
+ $stdin = @stdin
16
+ $stdout = @stdout
17
+
18
+ # Run our normal Thor app the way we know and love.
19
+ Mkmatter::App::CLI.start(@argv)
20
+
21
+ # Thor::Base#start does not have a return value, assume success if no exception is raised.
22
+ 0
23
+ rescue StandardError => e
24
+ # The ruby interpreter would pipe this to STDERR and exit 1 in the case of an unhandled exception
25
+ b = e.backtrace
26
+ @stderr.puts("#{b.shift}: #{e.message} (#{e.class})")
27
+ @stderr.puts(b.map {|s| "\tfrom #{s}"}.join("\n"))
28
+ 1
29
+ rescue SystemExit => e
30
+ e.status
31
+ ensure
32
+ # TODO: reset your app here, free up resources, etc.
33
+ # Examples:
34
+ # MyApp.logger.flush
35
+ # MyApp.logger.close
36
+ # MyApp.logger = nil
37
+ #
38
+ # MyApp.reset_singleton_instance_variables
39
+
40
+ # ...then we put the streams back.
41
+ $stderr = STDERR
42
+ $stdin = STDIN
43
+ $stdout = STDOUT
44
+ end
45
+
46
+ # Proxy our exit code back to the injected kernel.
47
+ @kernel.exit(exit_code)
48
+ end
49
+ end
50
+ end
51
+ end