scribedown 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/scribe +16 -0
- data/lib/generate/helpers.rb +19 -0
- data/lib/generate/renderer.rb +55 -0
- data/lib/res/resources.rb +89 -0
- data/lib/scribedown.rb +92 -0
- data/lib/section.rb +23 -0
- data/resources/csv_template.html.erb +20 -0
- data/resources/default.yml +12 -0
- data/resources/index.html.erb +9 -0
- data/resources/init/scribe.yml +3 -0
- data/resources/init/sections/default_section.md +5 -0
- data/resources/init/sections/info.csv +3 -0
- data/resources/section.html.erb +3 -0
- data/resources/style.css +13 -0
- metadata +86 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3493d9a579a7cb5cfb48987431d573d247f81e2e
|
4
|
+
data.tar.gz: f8c2f8412822c383ddc0064f319765dab602b796
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4c2f1a1d58274426b75f4a8af7010c6416a677af90ba9e07ce70ca20f48f77c192b0e22f88e9bea054d2c11251c7192d10830114df7fc09ea4a9f0c1ca354641
|
7
|
+
data.tar.gz: a2ddf98487a151031a8203533b69fcee56cb1ad4f1b5f66b3778fd78a2bfb42eaa82c1c4bbd5ada5e0d9f2bdf5f34a4e7ccbd1d9991a902d8c62f8a4153e96c1
|
data/bin/scribe
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'scribedown'
|
4
|
+
|
5
|
+
primary_arg = ARGV[0]
|
6
|
+
|
7
|
+
case primary_arg
|
8
|
+
when 'i', 'init'
|
9
|
+
ScribeDown.init
|
10
|
+
when 'g', 'generate'
|
11
|
+
ScribeDown.generate
|
12
|
+
when 'c', 'create'
|
13
|
+
ARGV[1..-1].each do |name|
|
14
|
+
ScribeDown.new_section(name)
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative '../res/resources'
|
2
|
+
|
3
|
+
module ScribeDown
|
4
|
+
module Renderer
|
5
|
+
def self.link_to(text, url, options={})
|
6
|
+
extras = options.map {|k,v| "#{k}=\"#{v}\"" }.join ' '
|
7
|
+
"<a href=\"#{url}\" #{extras}>#{text}</a>"
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.stylesheet_tag(file_name)
|
11
|
+
"<style>\n" + Res.read_file(file_name) + "\n</style>"
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.image_tag(url, options={})
|
15
|
+
extras = options.map {|k,v| "#{k}=\"#{v}\"" }.join ' '
|
16
|
+
"<img src=\"#{url}\" #{extras}/>"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require_relative '../res/resources'
|
2
|
+
require_relative 'helpers'
|
3
|
+
require 'pdfkit'
|
4
|
+
|
5
|
+
module ScribeDown
|
6
|
+
module Renderer
|
7
|
+
@@settings = nil
|
8
|
+
@@sections = nil
|
9
|
+
@@templates = nil
|
10
|
+
|
11
|
+
def self.head_tags
|
12
|
+
rendered = Array.new
|
13
|
+
@@settings[:styles].each do |style|
|
14
|
+
rendered.push(stylesheet_tag style)
|
15
|
+
end
|
16
|
+
rendered.join "\n\n"
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.content
|
20
|
+
rendered_sections = Array.new
|
21
|
+
@@sections.each do |section|
|
22
|
+
rendered_sections.push render_section(section)
|
23
|
+
end
|
24
|
+
rendered_sections.join "\n\n"
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.render_section(section)
|
28
|
+
if @@templates.has_key? section.container
|
29
|
+
template = @@templates[section.container]
|
30
|
+
else
|
31
|
+
template = Res.read_file(section.container, format: :plain)
|
32
|
+
@@templates[section.container] = template
|
33
|
+
end
|
34
|
+
content = Res.read_file(section.path, format: section.format.to_sym, binding: binding)
|
35
|
+
Res.erb_contents(template, binding)
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.add(file_name, options={})
|
39
|
+
options[:binding] = binding
|
40
|
+
Res.read_file(file_name, options)
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.to_html(sections, settings)
|
44
|
+
@@settings = settings
|
45
|
+
@@sections = sections
|
46
|
+
@@templates = Hash.new
|
47
|
+
title ||= settings[:title]
|
48
|
+
return Res.read_file(settings[:base], binding: binding)
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.to_pdf(html_content)
|
52
|
+
PDFKit.new(html_content).to_pdf
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'kramdown'
|
2
|
+
require 'yaml'
|
3
|
+
require 'erb'
|
4
|
+
require 'csv'
|
5
|
+
|
6
|
+
module ScribeDown
|
7
|
+
module Res
|
8
|
+
def self.root(file=nil)
|
9
|
+
path = File.expand_path '../..', File.dirname(__FILE__)
|
10
|
+
if file
|
11
|
+
path += '/' + file
|
12
|
+
end
|
13
|
+
return path
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.read_res(res_name)
|
17
|
+
File.open(self.root + '/resources/' + res_name).read()
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.read_file(file_name, options={})
|
21
|
+
binding = options[:binding]
|
22
|
+
format = options[:format]
|
23
|
+
only_in_fs = options[:in_fs]
|
24
|
+
|
25
|
+
if File.exist? file_name
|
26
|
+
name = file_name
|
27
|
+
elsif File.exist?(root('resources/' + file_name)) && !only_in_fs
|
28
|
+
name = root('resources/' + file_name)
|
29
|
+
else
|
30
|
+
raise "File or resource does not exist: #{file_name}"
|
31
|
+
end
|
32
|
+
|
33
|
+
contents = File.open(name).read()
|
34
|
+
if format == :plain
|
35
|
+
return contents
|
36
|
+
end
|
37
|
+
if binding && (name.end_with?('.erb') || format == :erb)
|
38
|
+
name = name.chomp('.erb')
|
39
|
+
contents = erb_contents(contents, binding)
|
40
|
+
end
|
41
|
+
if name.end_with?('.md') || name.end_with?('.markdown') || format == :markdown
|
42
|
+
contents = markdown_contents(contents)
|
43
|
+
end
|
44
|
+
if name.end_with?('.csv') || format == :csv
|
45
|
+
contents = csv_contents(contents)
|
46
|
+
end
|
47
|
+
return contents
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.markdown_contents(content)
|
51
|
+
Kramdown::Document.new(content, :auto_ids => true).to_html
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.erb_contents(contents, bind)
|
55
|
+
ERB.new(contents).result bind
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.yaml_contents(contents)
|
59
|
+
res = YAML.load(contents)
|
60
|
+
symbolize(res)
|
61
|
+
return res
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.csv_contents(contents)
|
65
|
+
all = CSV.parse(contents)
|
66
|
+
headers = all[0]
|
67
|
+
return if headers == nil
|
68
|
+
data = all[1..-1]
|
69
|
+
data_classes = headers.map {|h| h.gsub(/\W+/, '-') }
|
70
|
+
|
71
|
+
read_file('csv_template.html.erb', binding: binding)
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.symbolize(hash)
|
75
|
+
hash.default_proc = proc do |h, k|
|
76
|
+
case k
|
77
|
+
when String then sym = k.to_sym; h[sym] if h.key?(sym)
|
78
|
+
when Symbol then str = k.to_s; h[str] if h.key?(str)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.create_file(path, contents='')
|
84
|
+
File.open(path, 'w') do |file|
|
85
|
+
file.write(contents)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
data/lib/scribedown.rb
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require_relative 'res/resources'
|
3
|
+
require_relative 'generate/helpers'
|
4
|
+
require_relative 'generate/renderer'
|
5
|
+
require_relative 'section'
|
6
|
+
|
7
|
+
module ScribeDown
|
8
|
+
def self.generate(options={})
|
9
|
+
begin
|
10
|
+
settings = Res.yaml_contents(Res.read_file('scribe.yml', in_fs: true))
|
11
|
+
rescue Exception => e
|
12
|
+
abort "FATAL: Not a scribedown directory. Unable to read scribe.yml.\n" + e.message
|
13
|
+
end
|
14
|
+
sections_yaml = settings[:sections]
|
15
|
+
sections = Array.new
|
16
|
+
|
17
|
+
lookup = lookup_files()
|
18
|
+
failed = Array.new
|
19
|
+
|
20
|
+
glob_default = Res.yaml_contents(Res.read_file('default.yml'))[:default]
|
21
|
+
defaults = settings[:default] || {}
|
22
|
+
|
23
|
+
if glob_default
|
24
|
+
defaults.merge! glob_default
|
25
|
+
end
|
26
|
+
Res.symbolize(defaults)
|
27
|
+
# Extra styles don't override the defaults
|
28
|
+
defaults[:styles] += defaults[:extra_styles] || []
|
29
|
+
|
30
|
+
sections_yaml.each do |section|
|
31
|
+
name = section
|
32
|
+
ops = defaults.clone
|
33
|
+
if section.is_a? Hash
|
34
|
+
name = section.select {|k, v| v == nil }.first.first
|
35
|
+
ops = ops.merge(section)
|
36
|
+
ops.delete(name)
|
37
|
+
end
|
38
|
+
path = lookup[name.downcase]
|
39
|
+
if path
|
40
|
+
ops[:path] = path
|
41
|
+
ops[:name] = name
|
42
|
+
sections.push Section.new(ops)
|
43
|
+
else
|
44
|
+
failed.push section
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
output = defaults[:output]
|
49
|
+
type = output['default']
|
50
|
+
html = Renderer.to_html sections, defaults
|
51
|
+
if type == 'all' || type == 'html'
|
52
|
+
Res.create_file(defaults[:output]['html'], html)
|
53
|
+
end
|
54
|
+
if type == 'all' || type == 'pdf'
|
55
|
+
pdf = Renderer.to_pdf html
|
56
|
+
Res.create_file(defaults[:output]['pdf'], pdf)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.lookup_files
|
61
|
+
file_lookup = Hash.new
|
62
|
+
Dir['**/*'].each do |file|
|
63
|
+
name = File.basename(file).split('.').first.downcase
|
64
|
+
file_lookup[name] = file
|
65
|
+
end
|
66
|
+
file_lookup
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.init
|
70
|
+
if File.exist? 'scribe.yml'
|
71
|
+
abort 'ScribeDown already initialised: scribe.yml exists'
|
72
|
+
end
|
73
|
+
FileUtils.cp_r(Res.root('resources/init/.'), '.')
|
74
|
+
# Res.create_file('scribe.yml', Res.read_res('scribe.yml'))
|
75
|
+
# Res.create_file('sections/default_section.md', Res.read_res('default_section.md'))
|
76
|
+
end
|
77
|
+
|
78
|
+
def self.new_section(name)
|
79
|
+
begin
|
80
|
+
settings = Res.yaml_contents(Res.read_file('scribe.yml', in_fs: true))
|
81
|
+
rescue
|
82
|
+
abort 'FATAL: Not a scribedown directory. Unable to read scribe.yml.'
|
83
|
+
end
|
84
|
+
new_name = name.split('.').first
|
85
|
+
if new_name == name
|
86
|
+
name = name + '.md'
|
87
|
+
end
|
88
|
+
settings[:sections].push new_name
|
89
|
+
Res.create_file('sections/' + name, '# ' + new_name)
|
90
|
+
Res.create_file('scribe.yml', settings.to_yaml)
|
91
|
+
end
|
92
|
+
end
|
data/lib/section.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
module ScribeDown
|
2
|
+
class Section
|
3
|
+
attr_accessor :options
|
4
|
+
|
5
|
+
def initialize(options={})
|
6
|
+
self.options = options
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_s
|
10
|
+
"(#{path}: #{options})"
|
11
|
+
end
|
12
|
+
|
13
|
+
def method_missing(method)
|
14
|
+
if options.has_key?(method.to_sym)
|
15
|
+
return self.options[method.to_sym]
|
16
|
+
elsif options.has_key?(method.to_s)
|
17
|
+
return self.options[method.to_s]
|
18
|
+
else
|
19
|
+
super.method_missing(method)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
<table id="<%= name.gsub(/\W+/, '-') %>">
|
2
|
+
<thead>
|
3
|
+
<tr>
|
4
|
+
<% headers.each do |header| %>
|
5
|
+
<th><%= header %></th>
|
6
|
+
<% end %>
|
7
|
+
</tr>
|
8
|
+
</thead>
|
9
|
+
<tbody>
|
10
|
+
<% data.each do |line| %>
|
11
|
+
<tr>
|
12
|
+
<% line.each_with_index do |el, idx| %>
|
13
|
+
<td class="<%= data_classes[idx] %>">
|
14
|
+
<%= el %>
|
15
|
+
</td>
|
16
|
+
<% end %>
|
17
|
+
</tr>
|
18
|
+
<% end %>
|
19
|
+
</tbody>
|
20
|
+
</table>
|
@@ -0,0 +1,5 @@
|
|
1
|
+
# Welcome to ScribeDown
|
2
|
+
|
3
|
+
This is the default section. You can turn it into HTML or PDF by running `scribe generate`.
|
4
|
+
|
5
|
+
You can add more files by adding to the _sections_ folder and appending the name to _scribe.yml_. This config file defines the order of the sections and how they should appear.
|
data/resources/style.css
ADDED
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: scribedown
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Will Richardson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-10-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: kramdown
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.8'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pdfkit
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.8'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.8'
|
41
|
+
description: Markdown for report writing
|
42
|
+
email: william.hamish@gmail.com
|
43
|
+
executables:
|
44
|
+
- scribe
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- bin/scribe
|
49
|
+
- lib/generate/helpers.rb
|
50
|
+
- lib/generate/renderer.rb
|
51
|
+
- lib/res/resources.rb
|
52
|
+
- lib/scribedown.rb
|
53
|
+
- lib/section.rb
|
54
|
+
- resources/csv_template.html.erb
|
55
|
+
- resources/default.yml
|
56
|
+
- resources/index.html.erb
|
57
|
+
- resources/init/scribe.yml
|
58
|
+
- resources/init/sections/default_section.md
|
59
|
+
- resources/init/sections/info.csv
|
60
|
+
- resources/section.html.erb
|
61
|
+
- resources/style.css
|
62
|
+
homepage: http://javanut.net/scribedown
|
63
|
+
licenses:
|
64
|
+
- MIT
|
65
|
+
metadata: {}
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
requirements: []
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 2.4.8
|
83
|
+
signing_key:
|
84
|
+
specification_version: 4
|
85
|
+
summary: Markdown into a PDF
|
86
|
+
test_files: []
|