mastalk 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 469ccc6e66622dc8192693e3c965bc027d07eaf1
4
- data.tar.gz: 52e67b6fd78a9332452b5dd78ac2eddca10cab88
3
+ metadata.gz: 220cf96953a354bbaf66f95e548280ea2f50608b
4
+ data.tar.gz: bedca3b3cbdaa206841548a6f419dc92ce54cc38
5
5
  SHA512:
6
- metadata.gz: b3fbae435c5646d1fc37da7864c955362b51b5055bf1ac826f914780d34b2c2bfedef7d4f5d0b1bdcadd8670dfdd97a54d88fa0a8f1caab477a09973e08256e6
7
- data.tar.gz: 8d5eab4f6c577485cb1eaeac6773a39eeb3a272945415c7a7104d867270548814852deccd5cbe57b2d2f2b292b792ee0f2220aeb9809256cf0255da516c5c663
6
+ metadata.gz: bc5650ba5306081a15c26257ac9b9c6c717e9580f3977414220a61766b56dfed9ad6fa549faae5ef5f95220d738881f49d80c09d914a64e5d1a40eb989f64c8c
7
+ data.tar.gz: e268d79c98be558d3f0aa2f5da4f75a9bc67d08bb3f918a688904a552b8171d7e5addddf5ecab6f0b290fe9f819148ff6c845b2adc38bce39a11352d745605ec
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ *.DS_Store
2
+ Gemfile.lock
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.2
4
+ - 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/README.md ADDED
@@ -0,0 +1,174 @@
1
+ # MAStalk [![Build Status](https://travis-ci.org/moneyadviceservice/mastalk.svg)](https://travis-ci.org/moneyadviceservice/mastalk)
2
+
3
+ The Money Advice Service's Markdown extension language.
4
+
5
+ ## Usage
6
+
7
+ ```
8
+ gem install mastalk
9
+ ```
10
+
11
+ ```
12
+ Mastalk::Document.new("markdown").to_html
13
+ ```
14
+
15
+ ## Components
16
+
17
+ ### Add Action
18
+ `.add-action` box
19
+
20
+ ```
21
+ ^[Help to Buy schemes FAQs](/en/articles/help-to-buy-schemes-faqs)^
22
+ ```
23
+
24
+ Outputs:
25
+
26
+ ```
27
+ <div class="add-action">
28
+ <p><a href="/en/articles/help-to-buy-schemes-faqs">Help to Buy schemes FAQs</a></p>
29
+ </div>
30
+ ```
31
+
32
+
33
+ ### Callout
34
+
35
+ `.callout`
36
+
37
+ ```
38
+ $=callout
39
+ # Budgeting tips
40
+ In 1985, average first-time buyers needed a deposit of 5% to buy a home - in 2012, this had increased to 20%
41
+ *Source: HMS Treasury*
42
+ =$
43
+ ```
44
+
45
+ Outputs:
46
+
47
+ ```
48
+ <div class="callout">
49
+ <h3>Budgeting tips</h3>
50
+ <p>In 1985, average first-time buyers needed a deposit of 5% to buy a home - in 2012, this had increased to 20%
51
+ <br><strong>Source: HM Treasury </strong>
52
+ </p>
53
+ </div>
54
+ ```
55
+
56
+ ### Collapsible header
57
+
58
+ ```
59
+ $=
60
+ # Before you borrow
61
+ =$
62
+
63
+ $-
64
+ Find out if you need to borrow money and whether you can afford it. Learn how to work out the true cost of borrowing.
65
+
66
+ Taking control of debt
67
+
68
+ Where to get free debt advice, how to speak to the people you owe money to, and tips to help you pay back your debts in the right order.
69
+ -$
70
+ ```
71
+
72
+ Outputs:
73
+
74
+ ```
75
+ <div class="collapsible is-on">
76
+ <button class="unstyled-button">
77
+ <span class="icon icon--toggle"></span>
78
+ <span class="visually-hidden js-collapsable-hidden">hide </span>
79
+ Before you borrow
80
+ </button>
81
+ </div>
82
+
83
+ <div class="collapsible-section is-on" aria-hidden="false">
84
+ <p>Find out if you need to borrow money and whether you can afford it. Learn how to work out the true cost of borrowing.</p>
85
+ <p>Taking control of debt</p>
86
+ <p>Where to get free debt advice, how to speak to the people you owe money to, and tips to help you pay back your debts in the right order.</p>
87
+ </div>
88
+
89
+ ```
90
+
91
+ ### Ticks
92
+
93
+ ```
94
+ $yes-no
95
+ [y] You should do this
96
+ [y] and then do this
97
+ [y] and finally this
98
+ [n] You should not do this
99
+ [n] or this
100
+ [n] and definitely not do this
101
+ $end
102
+ ```
103
+
104
+ Outputs:
105
+
106
+ ```
107
+ <ul class="yes-no">
108
+ <li class="yes">You should do this</li>
109
+ <li class="yes">and then do this</li>
110
+ <li class="yes">and finally this</li>
111
+ <li class="no">You should not do this</li>
112
+ <li class="no">or this</li>
113
+ <li class="no">and definitely not do this</li>
114
+ </ul>
115
+ ```
116
+
117
+ ### Video
118
+
119
+ `.video-wrapper`
120
+
121
+ ```
122
+ ({5n1nixLSrQI})
123
+
124
+ ```
125
+
126
+ Outputs:
127
+
128
+ ```
129
+ <iframe
130
+ frameborder="0"
131
+ height="413"
132
+ width="680"
133
+ src= "https://www.youtube.com/embed/5n1nixLSrQI"
134
+ title="Video">
135
+ </iframe>
136
+ ```
137
+
138
+ ### Action Item
139
+
140
+ `.action-item`
141
+
142
+ ```
143
+ $action
144
+ ## Header
145
+ $collapsable
146
+ $why
147
+ ### Why?
148
+ Your 'Cash ISA allowance
149
+ $why
150
+ $how
151
+ ### How?
152
+ If you already have an ISA
153
+ $how
154
+ $collapsable
155
+ $item
156
+ ```
157
+
158
+ Outputs:
159
+ ```
160
+ <div class="action-item">
161
+ <h2 id="header" role="heading" aria-level="2">Header</h2>
162
+ <div class="collapsable">
163
+ <div class="why">
164
+ <h3 id="why" role="heading" aria-level="3">Why?</h3>
165
+ <p>Your ‘Cash ISA allowance</p>
166
+ </div>
167
+ <div class="how">
168
+ <h3 id="how" role="heading" aria-level="3">How?</h3>
169
+ <p>If you already have an ISA</p>
170
+ </div>
171
+ </div>
172
+ </div>
173
+ ```
174
+
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require 'rspec/core/rake_task'
2
+
3
+ RSpec::Core::RakeTask.new(:spec)
4
+ task :default => :spec
@@ -0,0 +1,45 @@
1
+ require 'erb'
2
+
3
+ module Mastalk
4
+ # Extension DSL for adding new
5
+ # mastalk snippets.
6
+ #
7
+ # Add new snippets in the form:
8
+ # # start_tag, end_tag, new_line_ending
9
+ #
10
+ # <p>replacement html <%= body %></p>
11
+ module Extensions
12
+ SNIPPETS_FOLDER=File.join(File.dirname(__FILE__), 'snippets')
13
+ @@extensions = []
14
+
15
+ def extension(start, stop = nil, new_line = false, &block)
16
+ re_start = Regexp.escape(start)
17
+ re_stop = stop == '$' ? stop : Regexp.escape(stop || start)
18
+ regex = Regexp.new("#{re_start}(.*)(#{re_stop})", new_line ? 0 : Regexp::MULTILINE)
19
+ @@extensions << [regex, block]
20
+ end
21
+
22
+ def extensions
23
+ return @@extensions unless @@extensions.empty?
24
+
25
+ Dir.foreach(SNIPPETS_FOLDER) do |file|
26
+ next if file == '.' || file == '..'
27
+ content = File.read(File.join(SNIPPETS_FOLDER, file))
28
+ start, stop, new_line = args(content)
29
+ extension(start, stop, new_line == 'false') do |body|
30
+ ERB.new(remove_syntax_from(content)).result(binding)
31
+ end
32
+ end
33
+
34
+ @@extensions
35
+ end
36
+
37
+ def args(content)
38
+ content.match(/#(.*)\n\n/m).captures.first.split(',').map(&:strip)
39
+ end
40
+
41
+ def remove_syntax_from(content)
42
+ content.split(/#(.*)\n\n/).last
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,5 @@
1
+ # $action, $item
2
+
3
+ <div class='action-item'>
4
+ <%= Mastalk::Document.new(body.strip).to_html %>
5
+ </div>
@@ -0,0 +1,5 @@
1
+ # ^
2
+
3
+ <div class='add-action'>
4
+ <%= Mastalk::Document.new(body.strip).to_html %>
5
+ </div>
@@ -0,0 +1,5 @@
1
+ # $=callout, =$
2
+
3
+ <div class='callout'>
4
+ <%= Mastalk::Document.new(body.strip).to_html %>
5
+ </div>
@@ -0,0 +1,5 @@
1
+ # $-, -$
2
+
3
+ <div class='collapsible-section'>
4
+ <%= Mastalk::Document.new(body.strip).to_html %>
5
+ </div>
@@ -0,0 +1,5 @@
1
+ # $collapsable
2
+
3
+ <div class='collapsable'>
4
+ <%= Mastalk::Document.new(body.strip).to_html %>
5
+ </div>
@@ -0,0 +1,9 @@
1
+ # $=, =$
2
+
3
+ <div class="collapsible">
4
+ <button class="unstyled-button">
5
+ <span class="icon icon--toggle"></span>
6
+ <span class="visually-hidden js-collapsable-hidden"></span>
7
+ <%= Mastalk::Document.new(body).to_html %>
8
+ </button>
9
+ </div>
@@ -0,0 +1,5 @@
1
+ # $how
2
+
3
+ <div class='how'>
4
+ <%= Mastalk::Document.new(body.strip).to_html %>
5
+ </div>
@@ -0,0 +1,3 @@
1
+ # [n], $, false
2
+
3
+ <li class='no'><%= body.strip.gsub("\n", '') %></li>
@@ -0,0 +1,5 @@
1
+ # $yes-no, $end
2
+
3
+ <ul class='yes-no'>
4
+ <%= Mastalk::Document.new(body).to_html %>
5
+ </ul>
@@ -0,0 +1,9 @@
1
+ # ({, })
2
+
3
+ <iframe
4
+ frameborder="0"
5
+ height="413"
6
+ width="680"
7
+ src= "<%= "https://www.youtube.com/embed/#{body}" %>"
8
+ title="Video">
9
+ </iframe>
@@ -0,0 +1,5 @@
1
+ # $why
2
+
3
+ <div class='why'>
4
+ <%= Mastalk::Document.new(body.strip).to_html %>
5
+ </div>
@@ -0,0 +1,3 @@
1
+ # [y], $, false
2
+
3
+ <li class='yes'><%= body.strip.gsub("\n", '') %></li>
data/mastalk.gemspec ADDED
@@ -0,0 +1,19 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'mastalk'
6
+ s.version = '0.1.2'
7
+ s.date = '2014-10-31'
8
+ s.summary = 'mastalk'
9
+ s.description = 'Mastalk markdown extension language'
10
+ s.authors = ['Douglas Roper']
11
+ s.email = 'dougdroper@gmail.com'
12
+ s.files = `git ls-files`.split($/)
13
+ s.homepage = 'https://github.com/moneyadviceservice/mastalk'
14
+ s.license = 'MIT'
15
+
16
+ s.add_runtime_dependency 'kramdown', '~> 1.5.0', '>= 1.5.0'
17
+ s.add_development_dependency 'rspec', '~> 3.1.0', '>= 3.1.0'
18
+ s.add_development_dependency 'rake', '~> 10.3.2', '>= 10.3.2'
19
+ end
@@ -0,0 +1,84 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mastalk::Document do
4
+
5
+ context 'Without mastalk syntax' do
6
+ let(:context) { "###test\nwith markdown" }
7
+ let(:expected) { "<h3 id=\"test\">test</h3>\n<p>with markdown</p>\n" }
8
+
9
+ subject { Mastalk::Document.new(context) }
10
+
11
+ it 'kramdown behaviour with no tags' do
12
+ expect(Mastalk::Document.new('test').to_html).to eq("<p>test</p>\n")
13
+ end
14
+
15
+ it 'converts to html' do
16
+ expect(subject.to_html).to eq(expected)
17
+ end
18
+
19
+ context 'multiline' do
20
+ let(:expected) { "<h3 id=\"test\">TEST</h3>\n\n<p>with other stuff</p>\n\n" }
21
+ let(:context) { "### TEST\r\n\r\nwith other stuff\r\n\r\n " }
22
+
23
+ it 'converts to html' do
24
+ expect(subject.to_html).to eq(expected)
25
+ end
26
+ end
27
+ end
28
+
29
+ subject { Mastalk::Document.new(source) }
30
+
31
+ let(:expected) { "<div class=\"test\">test</div>\n" }
32
+
33
+ context 'custom extension' do
34
+ let(:source) { '$Etest$E' }
35
+
36
+ it 'pre-processes custom tags' do
37
+ subject.extension('$E') { |body| "<div class='test'>#{body}</div>" }
38
+ expect(subject.to_html).to eq(expected)
39
+ end
40
+
41
+ context 'multi line' do
42
+ let(:source) { '$Etest$E$Shello$FIN' }
43
+ let(:expected) { "<div class=\"test\">test</div>\n<div class=\"test2\">hello</div>\n" }
44
+
45
+ it 'processes multi line' do
46
+ subject.extension('$E') { |body| "<div class='test'>#{body}</div>" }
47
+ subject.extension('$S', '$FIN') { |body| "<div class='test2'>#{body}</div>" }
48
+ expect(subject.to_html).to eq(expected)
49
+ end
50
+ end
51
+ end
52
+
53
+ context 'extension with start and stop' do
54
+ let(:source) { '$STARTtest$END' }
55
+
56
+ it 'pre-processes custom tags' do
57
+ subject.extension('$START', '$END') { |body| "<div class='test'>#{body}</div>" }
58
+ expect(subject.to_html).to eq(expected)
59
+ end
60
+ end
61
+
62
+ context 'extension with other extensions inside' do
63
+ let(:source) { "$why\n###header\nbody\n$why" }
64
+
65
+ let(:expected) { "<div class=\"why\">\n <h3 id=\"header\">header</h3>\n<p>body</p>\n\n</div>\n" }
66
+
67
+ it 'parses nested structures' do
68
+ expect(subject.to_html).to eq(expected)
69
+ end
70
+ end
71
+
72
+ context 'with newline as end' do
73
+ let(:source) { "$yes-no\n [y] yes \n [n] no \n $end $why\n###header\nbody\n$why" }
74
+
75
+ let(:expected) do
76
+ "<ul class=\"yes-no\">\n \n<li class=\"yes\">yes</li>\n\n<li class=\"no\">no</li>\n\n\n</ul>\n<div class=\"why\">
77
+ <h3 id=\"header\">header</h3>\n<p>body</p>\n\n</div>\n"
78
+ end
79
+
80
+ it 'pre-processes custom tags' do
81
+ expect(subject.to_html).to eq(expected)
82
+ end
83
+ end
84
+ end
@@ -0,0 +1 @@
1
+ require_relative '../lib/mastalk'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mastalk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Douglas Roper
@@ -76,8 +76,29 @@ executables: []
76
76
  extensions: []
77
77
  extra_rdoc_files: []
78
78
  files:
79
+ - ".gitignore"
80
+ - ".travis.yml"
81
+ - Gemfile
82
+ - README.md
83
+ - Rakefile
79
84
  - lib/mastalk.rb
80
- homepage: http://rubygems.org/
85
+ - lib/mastalk/extensions.rb
86
+ - lib/mastalk/snippets/action_item.html.erb
87
+ - lib/mastalk/snippets/add_action.html.erb
88
+ - lib/mastalk/snippets/callout.html.erb
89
+ - lib/mastalk/snippets/collabsible_section.html.erb
90
+ - lib/mastalk/snippets/collapsable.html.erb
91
+ - lib/mastalk/snippets/collapsible_header.html.erb
92
+ - lib/mastalk/snippets/how.html.erb
93
+ - lib/mastalk/snippets/no.html.erb
94
+ - lib/mastalk/snippets/ticks.html.erb
95
+ - lib/mastalk/snippets/video.html.erb
96
+ - lib/mastalk/snippets/why.html.erb
97
+ - lib/mastalk/snippets/yes.html.erb
98
+ - mastalk.gemspec
99
+ - spec/mastalk_spec.rb
100
+ - spec/spec_helper.rb
101
+ homepage: https://github.com/moneyadviceservice/mastalk
81
102
  licenses:
82
103
  - MIT
83
104
  metadata: {}