vimwiki_markdown 0.2.5 → 0.2.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aced79dd558ad5f073dc4e57fb727e95f7341dc5
4
- data.tar.gz: 49fc383b31e5def606eb2d08de02fe56549f1861
3
+ metadata.gz: f15a379fe2281d0a38bd24c2bdf359017dda45d1
4
+ data.tar.gz: 513869385056bd8578cb850cd8682f42efd93ecd
5
5
  SHA512:
6
- metadata.gz: b01693f8c5149f6c712335a64bd27bad5ac843705a6ac8b5a81b077326e250acf5974ce352c624a2f8be266d96732738cfe401d3140ae1211e131dd2fce94ec2
7
- data.tar.gz: 520c570ee5a4748672f9506d8b5e53d6ebc37554e681cd9c9eae50409f771d4b2734a0759d864ee9716b42da809a5271818af21906c768f17e0fd4bcf5334897
6
+ metadata.gz: a7c9cf57dc30a2f88b88bada446122a0406076d5d1a69f93fb0e3e0d53c9dc18fb714e57b412c024f39b281d782f1d2c411818d63fc8ab3f62eb868a3277f0ab
7
+ data.tar.gz: 937e1c37ac549bef675e94723fc9c7c1dd51a5aa8540de506dad665d9460cdb253a2495b202bd91f030a9f27191beb1e05dc3499d6fce325bbd7c6010c7139a8
data/README.md CHANGED
@@ -59,6 +59,17 @@ to [this commit](https://github.com/patrickdavey/vimwiki_markdown/commit/8645883
59
59
  It will get rewritten with the relative path to the root
60
60
  of the site (e.g. `./` or `../../` etc)
61
61
 
62
+ #### Using Custom Template Tag
63
+
64
+ Including a line with `%template <template name>` in any of your Vimwiki pages will will force the generator to use `<template name>.tpl` rather than `default.tpl` for that page.
65
+
66
+ `<template name>` cannot contain any spaces
67
+
68
+ #### Using Custom Title Tag
69
+
70
+ Including a line with `%title <title name>` in any of your Vimwiki pages will force the generator to replace `%title%` in your template file with `<title name>` rather than the name of the file itself.
71
+ *You can have spaces in your titles now!*
72
+
62
73
  ## Contributing
63
74
 
64
75
  Pull requests are very welcome, especially if you want to implement some of the
@@ -1,3 +1,6 @@
1
+ ## 0.2.6 [Jan 18 2018]
2
+ Add %template and %title options
3
+
1
4
  ## 0.2.4 [Jan 01 2017]
2
5
  Make directory links work correctly. If you now link to
3
6
  a directory [somedir](somedir/) then that link will be preserved
@@ -26,7 +26,7 @@ module VimwikiMarkdown
26
26
 
27
27
  attr_reader :force, :syntax, :extension, :output_dir,
28
28
  :input_file, :css_file, :template_path,
29
- :template_default, :template_ext, :root_path
29
+ :template_default, :template_ext, :root_path, :tags
30
30
 
31
31
  =begin force : [0/1] overwrite an existing file
32
32
  syntax : the syntax chosen for this wiki
@@ -54,10 +54,26 @@ module VimwikiMarkdown
54
54
  @template_ext = arguments[TEMPLATE_EXT]
55
55
  @root_path = arguments[ROOT_PATH]
56
56
  @root_path = "./" if @root_path == "-"
57
+ @tags = pull_tags
57
58
  raise "Must be markdown" unless syntax == 'markdown'
58
59
  end
59
60
 
61
+ def get_file_contents
62
+ file = File.open(input_file, "r")
63
+ file.read
64
+ end
65
+
66
+ def pull_tags
67
+ tags = Hash.new
68
+ get_file_contents.split("\n").each do |li|
69
+ tags['template'] = li.split.last if (li[/%template \S+./])
70
+ tags['title'] = li.sub(/%title /, '') if (li[/%title .+/])
71
+ end
72
+ return tags
73
+ end
74
+
60
75
  def template_filename
76
+ return "#{template_path}#{tags['template']}#{template_ext}" if @tags['template']
61
77
  "#{template_path}#{template_default}#{template_ext}"
62
78
  end
63
79
 
@@ -66,11 +82,12 @@ module VimwikiMarkdown
66
82
  end
67
83
 
68
84
  def title
85
+ return File.basename(tags['title'], ".md").split(/ |\_/).map(&:capitalize).join(" ") if @tags['title']
69
86
  File.basename(input_file, ".md").capitalize
70
87
  end
71
88
 
72
89
  def output_fullpath
73
- "#{output_dir}#{title.parameterize}.html"
90
+ "#{output_dir}#{File.basename(input_file, ".md")}.html"
74
91
  end
75
92
 
76
93
  private
@@ -1,3 +1,3 @@
1
1
  module VimwikiMarkdown
2
- VERSION = "0.2.5"
2
+ VERSION = "0.2.6"
3
3
  end
@@ -13,6 +13,7 @@ class VimwikiMarkdown::WikiBody
13
13
  def to_s
14
14
  @markdown_body = get_wiki_markdown_contents
15
15
  fixlinks
16
+ remove_tags
16
17
  github_markup = GitHub::Markup.render('README.markdown', markdown_body)
17
18
  pipeline = HTML::Pipeline.new [
18
19
  HTML::Pipeline::SyntaxHighlightFilter,
@@ -60,4 +61,13 @@ class VimwikiMarkdown::WikiBody
60
61
  end
61
62
  end
62
63
 
64
+ def remove_tags
65
+ @markdown_body.gsub!(/%template \S+/) do
66
+ ""
67
+ end
68
+ @markdown_body.gsub!(/%title \S+/) do
69
+ ""
70
+ end
71
+ end
72
+
63
73
  end
@@ -3,17 +3,31 @@ require 'vimwiki_markdown/options'
3
3
 
4
4
  module VimwikiMarkdown
5
5
  describe Options do
6
- subject { Options.new }
6
+ let(:markdown_file_content) {wiki_template_title_markdown}
7
+ let(:options) { Options.new }
8
+ subject {options}
7
9
 
8
10
  context "no options passed" do
9
11
  before do
12
+ allow(File).to receive(:open).and_return(StringIO.new("# title \n ## subtitle"))
10
13
  allow(Options).to receive(:arguments).and_return(Options::DEFAULTS)
11
14
  end
12
15
 
13
16
  its(:force) { should be(true) }
14
17
  its(:syntax) { should eq('markdown') }
15
- its(:output_fullpath) { should eq("#{subject.output_dir}#{subject.title.parameterize}.html") }
18
+ its(:output_fullpath) { should eq("#{subject.output_dir}#{File.basename(subject.input_file, ".md")}.html") }
16
19
  its(:template_filename) { should eq('~/vimwiki/templates/default.tpl') }
17
20
  end
21
+
22
+ context "file with tags in it" do
23
+ before do
24
+ allow(File).to receive(:open).and_return(StringIO.new(markdown_file_content))
25
+ allow(Options).to receive(:arguments).and_return(Options::DEFAULTS)
26
+ end
27
+
28
+ its(:template_filename) { should eq('~/vimwiki/templates/alt_template.tpl') }
29
+ its(:title) { should eq('Super Cool Title')}
30
+ end
31
+
18
32
  end
19
33
  end
@@ -7,11 +7,13 @@ require 'rspec-html-matchers'
7
7
  module VimwikiMarkdown
8
8
  describe Template do
9
9
  let(:options) { Options.new }
10
+ let(:markdown_file_content) {wiki_index_markdown}
10
11
 
11
12
  context "template" do
12
13
 
13
14
  subject { Template.new(options).to_s }
14
15
  before do
16
+ allow(File).to receive(:open).and_return(StringIO.new(markdown_file_content))
15
17
  allow(Options).to receive(:arguments).and_return(Options::DEFAULTS)
16
18
  allow(File).to receive(:open).with(options.template_filename,"r").and_return(StringIO.new(wiki_template))
17
19
  end
@@ -22,6 +24,7 @@ module VimwikiMarkdown
22
24
 
23
25
  context "missing pygments" do
24
26
  before do
27
+ allow(File).to receive(:open).and_return(StringIO.new(markdown_file_content))
25
28
  allow(Options).to receive(:arguments).and_return(Options::DEFAULTS)
26
29
  end
27
30
 
@@ -33,6 +36,7 @@ module VimwikiMarkdown
33
36
 
34
37
  context "using %root_path%" do
35
38
  before do
39
+ allow(File).to receive(:open).and_return(StringIO.new(markdown_file_content))
36
40
  allow(Options).to receive(:arguments).and_return(Options::DEFAULTS)
37
41
  end
38
42
 
@@ -38,6 +38,18 @@ module VimwikiMarkdown
38
38
  expect(wiki_body.to_s).to match(/<a href="here.html">here<\/a>/)
39
39
  expect(wiki_body.to_s).to match(/<a href="there.html">there<\/a>/)
40
40
  end
41
+
42
+ it "must remove template tags" do
43
+ allow(wiki_body).to receive(:get_wiki_markdown_contents).and_return("%template test\n")
44
+ expect(wiki_body.to_s).not_to match(/%template/)
45
+ expect(wiki_body.to_s).not_to match(/test/)
46
+ end
47
+
48
+ it "must remove title tags" do
49
+ allow(wiki_body).to receive(:get_wiki_markdown_contents).and_return("%title test\n")
50
+ expect(wiki_body.to_s).not_to match(/%title/)
51
+ expect(wiki_body.to_s).not_to match(/test/)
52
+ end
41
53
  end
42
54
 
43
55
  end
@@ -110,6 +110,16 @@ def wiki_index_markdown
110
110
  "
111
111
  end
112
112
 
113
+ def wiki_template_title_markdown
114
+ "
115
+ %title super cool title\n
116
+ %template alt_template\n
117
+ ## Todo\n
118
+ 1. add template functionality\n
119
+ 2. add title functionality\n
120
+ "
121
+ end
122
+
113
123
  def wiki_template
114
124
  <<-WIKITEMPLATE
115
125
  <!DOCTYPE html>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vimwiki_markdown
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick Davey
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-04 00:00:00.000000000 Z
11
+ date: 2018-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -245,7 +245,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
245
245
  version: '0'
246
246
  requirements: []
247
247
  rubyforge_project:
248
- rubygems_version: 2.4.8
248
+ rubygems_version: 2.6.12
249
249
  signing_key:
250
250
  specification_version: 4
251
251
  summary: Converts a github flavoured markdown vimwiki file into html.