jekyll-lab-notebook-plugins 0.1.0

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: 2c7ed19617651e9d232b89512c6e8a0143fc3785
4
+ data.tar.gz: c759b550a9c5f19a94d23c2088056eb879613fcf
5
+ SHA512:
6
+ metadata.gz: f8b25e997dce9f305222a13d4a8c36f15f9d2a4d4bdbf04e5c9c42266852e7905a4f15e2a8b6d4c2b5f4839e6d10af7e1405c31da5d7df01683f87db24a5624f
7
+ data.tar.gz: 80ec47648f484c1c7a3d8211e660c38169c334beadbd6d089fa2222dc51c5cabbeeb1dfa5b60c5cdb88a15f0a4d23b977d6e391178be42849d114ea4a8404b13
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.gem
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at tamas@tamasnagy.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in jekyll-lab-notebook-plugins.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Tamas Nagy
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,21 @@
1
+ # jekyll-lab-notebook-plugins
2
+
3
+ A collection of plugins for super charging your electronic lab notebook. See <https://github.com/tlnagy/jekyll-lab-notebook> for more details.
4
+
5
+ ## Development
6
+
7
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
8
+
9
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
10
+
11
+ ## Contributing
12
+
13
+ Bug reports and pull requests are welcome on GitHub at https://github.com/tlnagy/jekyll-lab-notebook-plugins. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
14
+
15
+ ## License
16
+
17
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
18
+
19
+ ## Code of Conduct
20
+
21
+ Everyone interacting in the Jekyll::Lab::Notebook::Plugins project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/tlnagy/jekyll-lab-notebook-plugins/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "jekyll-lab-notebook-plugins"
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__)
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,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "jekyll-lab-notebook-plugins/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "jekyll-lab-notebook-plugins"
8
+ spec.version = JekyllLabNotebookPlugins::VERSION
9
+ spec.authors = ["Tamas Nagy"]
10
+ spec.email = ["tamas@tamasnagy.com"]
11
+
12
+ spec.summary = "A collection of Jekyll plugins for better electronic lab notebooks"
13
+ spec.homepage = "https://github.com/tlnagy/jekyll-lab-notebook-plugins"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_runtime_dependency "nokogiri", "~> 1.8"
24
+ spec.add_runtime_dependency "jekyll", "~> 3.5"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.15"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ end
data/lib/count_days.rb ADDED
@@ -0,0 +1,31 @@
1
+ module DayLister
2
+ require 'nokogiri'
3
+ require 'date'
4
+ require 'jekyll'
5
+
6
+ class DayListTag < Liquid::Tag
7
+ def initialize(tag_name, url, tokens)
8
+ super
9
+ end
10
+
11
+ def render(context)
12
+ # current directory
13
+ postlist = context.registers[:site].posts.docs
14
+
15
+ result = "{\n"
16
+ postlist.each do |post|
17
+ doc = Nokogiri::HTML::DocumentFragment.parse(post.content)
18
+
19
+ doc.search('h3').each do |header|
20
+ if dt = DateTime.parse(header.text.strip) rescue false
21
+ result += (dt + Rational(12, 24)).strftime('%s') + ": 4,\n"
22
+ end
23
+ end
24
+ end
25
+ result += "}"
26
+ result
27
+ end
28
+ end
29
+ end
30
+
31
+ Liquid::Template.register_tag('listdays', DayLister::DayListTag)
data/lib/embed_csv.rb ADDED
@@ -0,0 +1,43 @@
1
+ module CSVEmbedder
2
+ require 'csv'
3
+
4
+ class CSVTag < Liquid::Tag
5
+ def initialize(tag_name, url, tokens)
6
+ super
7
+ @url = url
8
+ end
9
+
10
+ def render(context)
11
+ # current directory
12
+ filedir = File.dirname(context.registers[:page]["path"])
13
+
14
+ csvpath = File.path(File.join(filedir, @url.strip))
15
+
16
+ table_tag = "<table>"
17
+ table_tag += '<caption>Data from here: <a href="'+ @url + '">' + @url + '</a></caption>'
18
+ count = 0
19
+ CSV.foreach(csvpath) do |row|
20
+ if count == 0
21
+ table_tag += "<thead>"
22
+ else
23
+ table_tag += "<tbody>"
24
+ end
25
+ table_tag += "<tr>"
26
+ for item in row
27
+ table_tag += "<td>#{item}</td>"
28
+ end
29
+ table_tag += "</tr>"
30
+ if count == 0
31
+ table_tag += "</thead>"
32
+ else
33
+ table_tag += "</tbody>"
34
+ end
35
+ count += 1
36
+ end
37
+
38
+ table_tag += "</table>"
39
+ end
40
+ end
41
+ end
42
+
43
+ Liquid::Template.register_tag('embedcsv', CSVEmbedder::CSVTag)
data/lib/embed_pdf.rb ADDED
@@ -0,0 +1,30 @@
1
+ module PDFEmbedder
2
+
3
+ require 'pathname'
4
+
5
+ class PDFTag < Liquid::Tag
6
+ def initialize(tag_name, url, tokens)
7
+ super
8
+ @url = url
9
+ end
10
+
11
+ def render(context)
12
+ # current directory
13
+ filedir = File.dirname(context.registers[:page]["path"])
14
+
15
+ # if the path is relative than we have escape up one level
16
+ if !Pathname.new(@url.strip).absolute?
17
+ pdfpath = File.path(File.join("..", @url.strip))
18
+ else
19
+ pdfpath = @url.strip
20
+ end
21
+
22
+ result = "<div class=\"pdf-wrapper\">"
23
+ result += "<embed src=\"#{pdfpath}\"/>"
24
+ result += "<div class=\"caption\">Original file: <a href=\"#{pdfpath}\">#{File.basename(pdfpath)}</a></div>"
25
+ result += "</div>"
26
+ end
27
+ end
28
+ end
29
+
30
+ Liquid::Template.register_tag('embedpdf', PDFEmbedder::PDFTag)
@@ -0,0 +1,7 @@
1
+ require "jekyll-lab-notebook-plugins/version"
2
+ require "count_days"
3
+ require "embed_csv"
4
+ require "embed_pdf"
5
+ require "jekyll-postfiles"
6
+ require "logtags"
7
+ require "thought_tag"
@@ -0,0 +1,3 @@
1
+ module JekyllLabNotebookPlugins
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,94 @@
1
+ # Adapted from https://github.com/nhoizey/jekyll-postfiles
2
+ # with minor changes will remove and use as separate gem
3
+ # once https://github.com/nhoizey/jekyll-postfiles/pull/9
4
+ # is merged
5
+ require "pathname"
6
+
7
+ module Jekyll
8
+
9
+ class PostFile < StaticFile
10
+
11
+ # Initialize a new PostFile.
12
+ #
13
+ # site - The Site.
14
+ # base - The String path to the <source>.
15
+ # dir - The String path of the source directory of the file (rel <source>).
16
+ # name - The String filename of the file.
17
+ def initialize(site, base, dir, name, dest)
18
+ super(site, base, dir, name)
19
+ @name = name
20
+ @dest = dest
21
+ end
22
+
23
+ # Obtain destination path.
24
+ #
25
+ # dest - The String path to the destination dir.
26
+ #
27
+ # Returns destination file path.
28
+ def destination(dest)
29
+ File.join(@dest, @name)
30
+ end
31
+ end
32
+
33
+ class PostFileGenerator < Generator
34
+
35
+ # Copy the files from post's folder.
36
+ #
37
+ # post - A Post which may have associated content.
38
+ def copy_post_files(post)
39
+
40
+ post_path = Pathname.new post.path
41
+ site = post.site
42
+ site_src_dir = Pathname.new site.source
43
+
44
+ # Jekyll.logger.warn(
45
+ # "[PostFiles]",
46
+ # "Current post: #{post_path[site_src_dir.length..-1]}"
47
+ # )
48
+
49
+ post_dir = post_path.dirname
50
+ dest_dir = Pathname.new(post.destination("")).dirname
51
+
52
+ # Count other Markdown files in the same directory
53
+ other_md_count = 0
54
+ other_md = Dir.glob(post_dir + '*.{md,markdown}', File::FNM_CASEFOLD) do |mdfilepath|
55
+ if mdfilepath != post_path.to_path
56
+ other_md_count += 1
57
+ end
58
+ end
59
+
60
+ contents = Dir.glob(post_dir + '**/*') do |filepath|
61
+ if filepath != post_path \
62
+ && !File.directory?(filepath) \
63
+ && !File.fnmatch?('*.{md,markdown}', filepath, File::FNM_EXTGLOB | File::FNM_CASEFOLD)
64
+ filepath = Pathname.new(filepath)
65
+ # Jekyll.logger.warn(
66
+ # "[PostFiles]",
67
+ # "-> attachment: #{filepath[site_src_dir.length..-1]}"
68
+ # )
69
+ if other_md_count > 0
70
+ Jekyll.logger.abort_with(
71
+ "[PostFiles]",
72
+ "Sorry, there can be only one Markdown file in each directory containing other assets to be copied by jekyll-postfiles"
73
+ )
74
+ end
75
+ relpath = filepath.relative_path_from(site_src_dir)
76
+ filedir, filename = relpath.dirname, relpath.basename
77
+
78
+ absfiledir = site_src_dir + filedir
79
+ new_dir = absfiledir.relative_path_from(post_dir)
80
+ site.static_files <<
81
+ PostFile.new(site, site_src_dir, filedir, filename, (dest_dir + new_dir).to_path)
82
+ end
83
+ end
84
+ end
85
+
86
+ # Generate content by copying files associated with each post.
87
+ def generate(site)
88
+ site.posts.docs.each do |post|
89
+ copy_post_files(post)
90
+ end
91
+ end
92
+ end
93
+
94
+ end
data/lib/logtags.rb ADDED
@@ -0,0 +1,182 @@
1
+ # Support for adding tags to daily log posts and miscellaneous fixes to date
2
+ # display
3
+
4
+ require 'fileutils'
5
+ require 'nokogiri'
6
+ require 'set'
7
+ require 'pathname'
8
+ require 'uri'
9
+
10
+ # Pre-render
11
+ #
12
+ # This is the first step. When posts are built, this block goes through and
13
+ # reads the markdown line by line to identify log entries by looking for headers
14
+ # followed by a parseable date. It then extracts the project tags that follow
15
+ # the date and constructs a hash/dict mapping log entries by their html ids
16
+ # (in the standard YYYYMMDD format) to an array of project tags. This block also
17
+ # removes the project tags and pretty formats things.
18
+ Jekyll::Hooks.register :posts, :pre_render do |post|
19
+ in_code_block = false
20
+
21
+ entrymap = Hash.new { |h, k| h[k] = Set.new }
22
+
23
+ converted_lines = post.content.split("\n").map do |line|
24
+
25
+ # skip code blocks
26
+ in_code_block = !in_code_block if line.match(/^```/)
27
+ next line if in_code_block
28
+
29
+ # drop lines that aren't markdown headers
30
+ matched = line.match(/^(#+) /)
31
+ next line unless matched
32
+
33
+ # drop headers that don't start with dates
34
+ DateTime.parse(line.strip) rescue next line
35
+
36
+ # pretty format dates
37
+ date = DateTime.parse(line.strip)
38
+ iddate = date.strftime("%Y%m%d")
39
+ displaydate = date.strftime("%a, %b %e")
40
+
41
+ # extract project tags
42
+ tags = line.strip.scan(/#([a-zA-Z0-9._-]{3,} ?)/)
43
+
44
+ # if project tags are detected for this entry then add it to the hash
45
+ if tags.length > 0
46
+ tags.each { |tag| entrymap[iddate].add(tag[0].strip) }
47
+ end
48
+
49
+ # replace markdown header with this nice html
50
+ "<h3 class=\"log-entry\" id=\"#{iddate}\">#{displaydate}</h3>"
51
+ end
52
+
53
+ # sort the hash so posts will be laid out chronologically on the project page
54
+ entrymap = Hash[ entrymap.sort_by { |key, val| key } ]
55
+
56
+ # save the hash for later processing
57
+ post.site.data["entrymap"] = entrymap
58
+
59
+ post.content = converted_lines.join("\n")
60
+ end
61
+
62
+ # Post-render
63
+ #
64
+ # This is the second step. Once the posts are converted to HTML, this block is
65
+ # called. It goes through and splits up each post into separate log entries and
66
+ # inserts the HTML version of these log entries into a hash that maps projects
67
+ # to entry HTMLs. It also goes and fixes relative links in the log entries so
68
+ # that images work once the HTML is copied over to the projects folder.
69
+ Jekyll::Hooks.register :posts, :post_render do |post|
70
+ # if this post has entries with project tags
71
+ if post.site.data["entrymap"].length > 0
72
+
73
+ # attempt to load a hash mapping tags to ids from the site data
74
+ if post.site.data["tagmap"] == nil
75
+ tagmap = {}
76
+ else
77
+ tagmap = post.site.data["tagmap"]
78
+ end
79
+
80
+ # create new array if key doesn't exist (default dictionary)
81
+ tagmap.default_proc = proc { |h, k| h[k] = [] }
82
+
83
+ doc = Nokogiri::HTML post.content
84
+
85
+ # iterate over each entry and its associated tags
86
+ post.site.data["entrymap"].each do |entry, tags|
87
+
88
+ new_node_set = Nokogiri::XML::NodeSet.new(doc)
89
+ orig = doc.at_css("h3.log-entry[id=\"#{entry}\"]")
90
+ new_node_set << orig
91
+ node = orig.next
92
+
93
+ # continue until we run out of sibling nodes or we hit the next log entry
94
+ while !node.nil? && node["class"] != "log-entry"
95
+ new_node_set << node
96
+ node = node.next
97
+ end
98
+
99
+ tags.each do |tag|
100
+ dir = post.site.config['projects_dir'] || 'projects'
101
+ old_path = post.url # convert to relative url since post.url is absolute
102
+ old_path[0] = ''
103
+ fix_links(new_node_set, old_path, File.join(dir, tag)) # fix rel links
104
+ content = new_node_set.to_html
105
+ # fix checkboxes
106
+ content.gsub! '<li>[ ]', '<li class="box task-list-item"><input type="checkbox" class="task-list-item-checkbox" disabled>'
107
+ content.gsub! '<li>[x]', '<li class="box_done task-list-item"><input type="checkbox" class="task-list-item-checkbox" value="on" disabled checked>'
108
+ tagmap[tag.strip].push(content)
109
+ end
110
+ end
111
+
112
+ post.site.data["tagmap"] = tagmap
113
+ end
114
+ end
115
+
116
+ # Post-write
117
+ #
118
+ # This is the last step. Once the posts are all written, we can build the
119
+ # project pages. This works by taking the mapping of projects to HTML fragments
120
+ # from previously and generating new pages for each project and injecting the
121
+ # HTML fragments into their respective pages.
122
+ Jekyll::Hooks.register :site, :post_write do |site|
123
+ dir = site.config['projects_dir'] || 'projects'
124
+ dest = site.config["destination"]
125
+
126
+ # load in the all generated HTML for the project page, we're going to clone
127
+ # this and inject our new content into it to avoid having to deal with liquid
128
+ template = File.read(File.join(dest, dir, 'index.html'))
129
+ doc = Nokogiri::HTML template
130
+
131
+ site.data["tagmap"].each_key do |tag|
132
+ path = File.join(dest, dir, tag)
133
+ FileUtils.mkdir_p path
134
+ File.open(File.join(path, "index.html"), 'w') do |f|
135
+ # inject new title
136
+ doc.at_css('h1.post-title').inner_html = "Project ##{tag} <a href=\"#latest\">&#8617;</a>"
137
+
138
+ # construct one body of HTML from all the separate fragments
139
+ new_node_set = Nokogiri::XML::NodeSet.new(doc)
140
+ site.data["tagmap"][tag].each do |content|
141
+ new_node_set << Nokogiri::HTML::fragment(content)
142
+ end
143
+
144
+ content = doc.at_css('div.post-content')
145
+
146
+ # skeletonize page and inject new content
147
+ content.children.remove rescue nil
148
+ content << new_node_set.to_html
149
+ content << "<div id=latest></div>"
150
+
151
+ f.write(doc.to_html)
152
+ end
153
+ end
154
+ end
155
+
156
+
157
+ # fixes relative paths for the new tag files
158
+ def fix_links(doc, old_path, new_path)
159
+ # figure out relative link mapping
160
+ prefix = Pathname.new(old_path).relative_path_from(Pathname.new(new_path))
161
+
162
+ url_tags = {
163
+ 'img' => 'src',
164
+ 'script' => 'src',
165
+ 'a' => 'href'
166
+ }
167
+
168
+ # grab all url links
169
+ doc.search(url_tags.keys.join(',')).each do |node|
170
+ url_param = url_tags[node.name]
171
+ src = node[url_param]
172
+
173
+ unless src.empty?
174
+ path = Pathname.new(src)
175
+ uri = URI.parse(src)
176
+ # only fix relative links and non http calls
177
+ if path.relative? && !%w( http https ).include?(uri.scheme)
178
+ node[url_param] = (prefix+path).to_s
179
+ end
180
+ end
181
+ end
182
+ end
@@ -0,0 +1,39 @@
1
+ module ThoughtTagger
2
+
3
+ class ThoughtTag < Liquid::Tag
4
+ def initialize(tag_name, markup, tokens)
5
+ @markup = markup
6
+ super
7
+ end
8
+
9
+ def render(context)
10
+ site = context.registers[:site]
11
+ converter = site.find_converter_instance(::Jekyll::Converters::Markdown)
12
+
13
+ result = "<div class=\"alert alert-info\" role=\"alert\">#{converter.convert(@markup).strip}</div>"
14
+ end
15
+ end
16
+ end
17
+
18
+ Liquid::Template.register_tag('thought', ThoughtTagger::ThoughtTag)
19
+
20
+ module NoteTagger
21
+
22
+ class NoteTag < Liquid::Tag
23
+ def initialize(tag_name, markup, tokens)
24
+ @markup = markup
25
+ super
26
+ end
27
+
28
+ def render(context)
29
+ site = context.registers[:site]
30
+ converter = site.find_converter_instance(::Jekyll::Converters::Markdown)
31
+
32
+ markup = converter.convert(@markup).strip[3..-1]
33
+ result = "<div class=\"alert alert-note\" role=\"alert\">"
34
+ result << "<p><span><strong>Note: </strong></span>#{markup}</div>"
35
+ end
36
+ end
37
+ end
38
+
39
+ Liquid::Template.register_tag('note', NoteTagger::NoteTag)
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-lab-notebook-plugins
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tamas Nagy
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-07-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
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: jekyll
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.5'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.15'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.15'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description:
70
+ email:
71
+ - tamas@tamasnagy.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - CODE_OF_CONDUCT.md
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - bin/console
83
+ - bin/setup
84
+ - jekyll-lab-notebook-plugins.gemspec
85
+ - lib/count_days.rb
86
+ - lib/embed_csv.rb
87
+ - lib/embed_pdf.rb
88
+ - lib/jekyll-lab-notebook-plugins.rb
89
+ - lib/jekyll-lab-notebook-plugins/version.rb
90
+ - lib/jekyll-postfiles.rb
91
+ - lib/logtags.rb
92
+ - lib/thought_tag.rb
93
+ homepage: https://github.com/tlnagy/jekyll-lab-notebook-plugins
94
+ licenses:
95
+ - MIT
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.6.11
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: A collection of Jekyll plugins for better electronic lab notebooks
117
+ test_files: []