peasy-document 0.1.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 +7 -0
- data/lib/peasy_document/engine.rb +59 -0
- data/lib/peasy_document/version.rb +5 -0
- data/lib/peasy_document.rb +4 -0
- metadata +49 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: d4c2cd633b059418143f29a98e63b5f20ec21d09ef5da05337223a0277e3e840
|
|
4
|
+
data.tar.gz: 9dd42742e3d2d59ed5c26a42c3e94719de97448b4e67e91b5763aa8879be26e3
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: bfbe33c3073cb44f9e804c9ccaa9d71e6f9896151ea974a11b91c8b5182db86ffa4578355dcc1a8ccd1cb0e8ec00efb56313d601078ba2021b46c1a6a337322c
|
|
7
|
+
data.tar.gz: 1f66a3af389dae425a8481223ea86488b6aea0b53fc25eae8c84c5fdc17243f25c861c742f9857b1b691619f2c3311f2dea9c0dbcb77c1e68e4e1c73238bcc9c
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "json"
|
|
4
|
+
require "csv"
|
|
5
|
+
require "yaml"
|
|
6
|
+
|
|
7
|
+
module PeasyDocument
|
|
8
|
+
module_function
|
|
9
|
+
|
|
10
|
+
def markdown_to_html(markdown)
|
|
11
|
+
html = markdown.dup
|
|
12
|
+
# Headers
|
|
13
|
+
html.gsub!(/^### (.+)$/, "<h3>\\1</h3>")
|
|
14
|
+
html.gsub!(/^## (.+)$/, "<h2>\\1</h2>")
|
|
15
|
+
html.gsub!(/^# (.+)$/, "<h1>\\1</h1>")
|
|
16
|
+
# Bold & italic
|
|
17
|
+
html.gsub!(/\*\*(.+?)\*\*/, "<strong>\\1</strong>")
|
|
18
|
+
html.gsub!(/\*(.+?)\*/, "<em>\\1</em>")
|
|
19
|
+
# Code
|
|
20
|
+
html.gsub!(/`(.+?)`/, "<code>\\1</code>")
|
|
21
|
+
# Links
|
|
22
|
+
html.gsub!(/\[(.+?)\]\((.+?)\)/, '<a href="\\2">\\1</a>')
|
|
23
|
+
# Line breaks → paragraphs
|
|
24
|
+
html.gsub!(/\n\n/, "</p>\n<p>")
|
|
25
|
+
"<p>#{html}</p>"
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def csv_to_json(csv_string)
|
|
29
|
+
rows = CSV.parse(csv_string, headers: true)
|
|
30
|
+
rows.map(&:to_h).to_json
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def json_to_csv(json_string)
|
|
34
|
+
data = JSON.parse(json_string)
|
|
35
|
+
return "" if data.empty?
|
|
36
|
+
CSV.generate do |csv|
|
|
37
|
+
csv << data.first.keys
|
|
38
|
+
data.each { |row| csv << row.values }
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def json_to_yaml(json_string)
|
|
43
|
+
data = JSON.parse(json_string)
|
|
44
|
+
data.to_yaml
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def yaml_to_json(yaml_string)
|
|
48
|
+
data = YAML.safe_load(yaml_string, permitted_classes: [Date, Time])
|
|
49
|
+
JSON.pretty_generate(data)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def json_format(json_string)
|
|
53
|
+
JSON.pretty_generate(JSON.parse(json_string))
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def json_minify(json_string)
|
|
57
|
+
JSON.generate(JSON.parse(json_string))
|
|
58
|
+
end
|
|
59
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: peasy-document
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- PeasyTools
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies: []
|
|
12
|
+
description: Document conversion library for Ruby — convert between Markdown, HTML,
|
|
13
|
+
CSV, JSON, and YAML formats. Uses Ruby stdlib (csv, json, yaml), zero external dependencies.
|
|
14
|
+
email:
|
|
15
|
+
- hello@peasytools.com
|
|
16
|
+
executables: []
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- lib/peasy_document.rb
|
|
21
|
+
- lib/peasy_document/engine.rb
|
|
22
|
+
- lib/peasy_document/version.rb
|
|
23
|
+
homepage: https://peasytools.com
|
|
24
|
+
licenses:
|
|
25
|
+
- MIT
|
|
26
|
+
metadata:
|
|
27
|
+
homepage_uri: https://peasytools.com
|
|
28
|
+
source_code_uri: https://github.com/peasytools/peasy-document-rb
|
|
29
|
+
changelog_uri: https://github.com/peasytools/peasy-document-rb/blob/main/CHANGELOG.md
|
|
30
|
+
documentation_uri: https://peasytools.com
|
|
31
|
+
bug_tracker_uri: https://github.com/peasytools/peasy-document-rb/issues
|
|
32
|
+
rdoc_options: []
|
|
33
|
+
require_paths:
|
|
34
|
+
- lib
|
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '3.0'
|
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
41
|
+
requirements:
|
|
42
|
+
- - ">="
|
|
43
|
+
- !ruby/object:Gem::Version
|
|
44
|
+
version: '0'
|
|
45
|
+
requirements: []
|
|
46
|
+
rubygems_version: 4.0.3
|
|
47
|
+
specification_version: 4
|
|
48
|
+
summary: Document conversion — Markdown, HTML, CSV, JSON, YAML
|
|
49
|
+
test_files: []
|