togostanza 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +15 -0
  5. data/Appraisals +7 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +29 -0
  9. data/Rakefile +9 -0
  10. data/bin/togostanza +5 -0
  11. data/gemfiles/activesupport_3.x.gemfile +7 -0
  12. data/gemfiles/activesupport_3.x.gemfile.lock +99 -0
  13. data/gemfiles/activesupport_4.x.gemfile +7 -0
  14. data/gemfiles/activesupport_4.x.gemfile.lock +107 -0
  15. data/lib/togostanza/application.rb +43 -0
  16. data/lib/togostanza/cli.rb +81 -0
  17. data/lib/togostanza/markdown.rb +39 -0
  18. data/lib/togostanza/stanza/base.rb +71 -0
  19. data/lib/togostanza/stanza/expression_map.rb +44 -0
  20. data/lib/togostanza/stanza/markdown.rb +37 -0
  21. data/lib/togostanza/stanza/querying.rb +43 -0
  22. data/lib/togostanza/stanza.rb +15 -0
  23. data/lib/togostanza/version.rb +3 -0
  24. data/lib/togostanza.rb +8 -0
  25. data/public/assets/stanza.css +113 -0
  26. data/public/assets/stanza.js +36 -0
  27. data/spec/dummy/app.rb +8 -0
  28. data/spec/dummy/bar_stanza/help.md +1 -0
  29. data/spec/dummy/bar_stanza/lib/bar_stanza.rb +3 -0
  30. data/spec/dummy/bar_stanza/stanza.rb +5 -0
  31. data/spec/dummy/bar_stanza/template.hbs +1 -0
  32. data/spec/dummy/foo_stanza/help.md +1 -0
  33. data/spec/dummy/foo_stanza/lib/foo_stanza.rb +3 -0
  34. data/spec/dummy/foo_stanza/stanza.rb +9 -0
  35. data/spec/dummy/foo_stanza/template.hbs +1 -0
  36. data/spec/features/help_spec.rb +13 -0
  37. data/spec/features/listing_spec.rb +17 -0
  38. data/spec/features/rendering_spec.rb +13 -0
  39. data/spec/features/resource_spec.rb +11 -0
  40. data/spec/lib/togostanza/stanza/base_spec.rb +79 -0
  41. data/spec/spec_helper.rb +17 -0
  42. data/templates/provider/Gemfile.erb +3 -0
  43. data/templates/provider/config.ru.erb +6 -0
  44. data/templates/stanza/Gemfile.erb +3 -0
  45. data/templates/stanza/gemspec.erb +20 -0
  46. data/templates/stanza/help.md.erb +22 -0
  47. data/templates/stanza/lib.rb.erb +4 -0
  48. data/templates/stanza/stanza.rb.erb +5 -0
  49. data/templates/stanza/template.hbs.erb +17 -0
  50. data/togostanza.gemspec +37 -0
  51. data/views/index.haml +9 -0
  52. data/views/layout.haml +13 -0
  53. metadata +321 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 73791980af93f171cb47540d0e3a4fe4edb007ab
4
+ data.tar.gz: 4f6a9c402d3a859f900f8e2a1b0815199d9af470
5
+ SHA512:
6
+ metadata.gz: 2299c7c8161f845fc547ee51096b859b008754eaea2b1ed14523d5135febfc7b9629949a243b86ea6627dbc6a0f6751e6a23474141448dde7a22eabbfca3bc57
7
+ data.tar.gz: de344269365ebbcc02e404cc7317ee0ef559da3978a62edb4eb192942286548f1fda02265bc921bec7d9130a4fe2a3a6829b386b4d30140130fe84f53309db4c
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/.travis.yml ADDED
@@ -0,0 +1,15 @@
1
+ language: ruby
2
+ cache: bundler
3
+
4
+ rvm:
5
+ - 1.9.3
6
+ - 2.0.0
7
+
8
+ gemfile:
9
+ - gemfiles/activesupport_3.x.gemfile
10
+ - gemfiles/activesupport_4.x.gemfile
11
+
12
+ bundler_args: --without production
13
+
14
+ notifications:
15
+ webhooks: https://idobata.io/hook/047eeb76-6f1f-4fc2-82f8-f8abceacd51e
data/Appraisals ADDED
@@ -0,0 +1,7 @@
1
+ appraise 'activesupport-3.x' do
2
+ gem 'activesupport', '~> 3.0'
3
+ end
4
+
5
+ appraise 'activesupport-4.x' do
6
+ gem 'activesupport', '~> 4.0'
7
+ end
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in togostanza-server.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Keita Urashima
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # TogoStanza
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'togostanza'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install togostanza
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'bundler/setup'
2
+
3
+ require 'appraisal'
4
+ require 'bundler/gem_tasks'
5
+ require 'rspec/core/rake_task'
6
+
7
+ RSpec::Core::RakeTask.new(:spec)
8
+
9
+ task :default => :spec
data/bin/togostanza ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'togostanza'
4
+
5
+ TogoStanza::CLI::Root.start
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activesupport", "~> 3.0"
6
+
7
+ gemspec :path=>"../"
@@ -0,0 +1,99 @@
1
+ PATH
2
+ remote: /home/ursm/src/togostanza-server
3
+ specs:
4
+ togostanza-server (0.0.1)
5
+ activesupport
6
+ flavour_saver
7
+ haml
8
+ hashie
9
+ parallel
10
+ redcarpet
11
+ sinatra
12
+ sinatra-contrib
13
+ sparql-client
14
+ thor
15
+
16
+ GEM
17
+ remote: https://rubygems.org/
18
+ specs:
19
+ activesupport (3.2.13)
20
+ i18n (= 0.6.1)
21
+ multi_json (~> 1.0)
22
+ addressable (2.3.5)
23
+ appraisal (0.5.2)
24
+ bundler
25
+ rake
26
+ backports (3.3.5)
27
+ capybara (2.1.0)
28
+ mime-types (>= 1.16)
29
+ nokogiri (>= 1.3.3)
30
+ rack (>= 1.0.0)
31
+ rack-test (>= 0.5.4)
32
+ xpath (~> 2.0)
33
+ diff-lcs (1.2.4)
34
+ ffi (1.9.0)
35
+ flavour_saver (0.3.1)
36
+ rltk (~> 2.2.0)
37
+ tilt
38
+ haml (4.0.3)
39
+ tilt
40
+ hashie (2.0.5)
41
+ i18n (0.6.1)
42
+ json_pure (1.8.1)
43
+ mime-types (1.25)
44
+ mini_portile (0.5.1)
45
+ multi_json (1.7.7)
46
+ net-http-persistent (2.9)
47
+ nokogiri (1.6.0)
48
+ mini_portile (~> 0.5.0)
49
+ parallel (0.9.0)
50
+ rack (1.5.2)
51
+ rack-protection (1.5.0)
52
+ rack
53
+ rack-test (0.6.2)
54
+ rack (>= 1.0)
55
+ rake (10.1.0)
56
+ rdf (1.0.9)
57
+ addressable (>= 2.3)
58
+ redcarpet (3.0.0)
59
+ rltk (2.2.1)
60
+ ffi (>= 1.0.0)
61
+ rspec (2.14.1)
62
+ rspec-core (~> 2.14.0)
63
+ rspec-expectations (~> 2.14.0)
64
+ rspec-mocks (~> 2.14.0)
65
+ rspec-core (2.14.4)
66
+ rspec-expectations (2.14.0)
67
+ diff-lcs (>= 1.1.3, < 2.0)
68
+ rspec-mocks (2.14.1)
69
+ sinatra (1.4.3)
70
+ rack (~> 1.4)
71
+ rack-protection (~> 1.4)
72
+ tilt (~> 1.3, >= 1.3.4)
73
+ sinatra-contrib (1.4.1)
74
+ backports (>= 2.0)
75
+ multi_json
76
+ rack-protection
77
+ rack-test
78
+ sinatra (~> 1.4.0)
79
+ tilt (~> 1.3)
80
+ sparql-client (1.0.4.1)
81
+ json_pure (>= 1.4)
82
+ net-http-persistent (>= 1.4)
83
+ rdf (>= 1.0)
84
+ thor (0.18.1)
85
+ tilt (1.4.1)
86
+ xpath (2.0.0)
87
+ nokogiri (~> 1.3)
88
+
89
+ PLATFORMS
90
+ ruby
91
+
92
+ DEPENDENCIES
93
+ activesupport (~> 3.0)
94
+ appraisal
95
+ bundler (~> 1.3)
96
+ capybara
97
+ rake
98
+ rspec
99
+ togostanza-server!
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activesupport", "~> 4.0"
6
+
7
+ gemspec :path=>"../"
@@ -0,0 +1,107 @@
1
+ PATH
2
+ remote: /home/ursm/src/togostanza-server
3
+ specs:
4
+ togostanza-server (0.0.1)
5
+ activesupport
6
+ flavour_saver
7
+ haml
8
+ hashie
9
+ parallel
10
+ redcarpet
11
+ sinatra
12
+ sinatra-contrib
13
+ sparql-client
14
+ thor
15
+
16
+ GEM
17
+ remote: https://rubygems.org/
18
+ specs:
19
+ activesupport (4.0.0)
20
+ i18n (~> 0.6, >= 0.6.4)
21
+ minitest (~> 4.2)
22
+ multi_json (~> 1.3)
23
+ thread_safe (~> 0.1)
24
+ tzinfo (~> 0.3.37)
25
+ addressable (2.3.5)
26
+ appraisal (0.5.2)
27
+ bundler
28
+ rake
29
+ atomic (1.1.10)
30
+ backports (3.3.5)
31
+ capybara (2.1.0)
32
+ mime-types (>= 1.16)
33
+ nokogiri (>= 1.3.3)
34
+ rack (>= 1.0.0)
35
+ rack-test (>= 0.5.4)
36
+ xpath (~> 2.0)
37
+ diff-lcs (1.2.4)
38
+ ffi (1.9.0)
39
+ flavour_saver (0.3.1)
40
+ rltk (~> 2.2.0)
41
+ tilt
42
+ haml (4.0.3)
43
+ tilt
44
+ hashie (2.0.5)
45
+ i18n (0.6.4)
46
+ json_pure (1.8.1)
47
+ mime-types (1.25)
48
+ mini_portile (0.5.1)
49
+ minitest (4.7.5)
50
+ multi_json (1.7.7)
51
+ net-http-persistent (2.9)
52
+ nokogiri (1.6.0)
53
+ mini_portile (~> 0.5.0)
54
+ parallel (0.9.0)
55
+ rack (1.5.2)
56
+ rack-protection (1.5.0)
57
+ rack
58
+ rack-test (0.6.2)
59
+ rack (>= 1.0)
60
+ rake (10.1.0)
61
+ rdf (1.0.9)
62
+ addressable (>= 2.3)
63
+ redcarpet (3.0.0)
64
+ rltk (2.2.1)
65
+ ffi (>= 1.0.0)
66
+ rspec (2.14.1)
67
+ rspec-core (~> 2.14.0)
68
+ rspec-expectations (~> 2.14.0)
69
+ rspec-mocks (~> 2.14.0)
70
+ rspec-core (2.14.4)
71
+ rspec-expectations (2.14.0)
72
+ diff-lcs (>= 1.1.3, < 2.0)
73
+ rspec-mocks (2.14.1)
74
+ sinatra (1.4.3)
75
+ rack (~> 1.4)
76
+ rack-protection (~> 1.4)
77
+ tilt (~> 1.3, >= 1.3.4)
78
+ sinatra-contrib (1.4.1)
79
+ backports (>= 2.0)
80
+ multi_json
81
+ rack-protection
82
+ rack-test
83
+ sinatra (~> 1.4.0)
84
+ tilt (~> 1.3)
85
+ sparql-client (1.0.4.1)
86
+ json_pure (>= 1.4)
87
+ net-http-persistent (>= 1.4)
88
+ rdf (>= 1.0)
89
+ thor (0.18.1)
90
+ thread_safe (0.1.2)
91
+ atomic
92
+ tilt (1.4.1)
93
+ tzinfo (0.3.37)
94
+ xpath (2.0.0)
95
+ nokogiri (~> 1.3)
96
+
97
+ PLATFORMS
98
+ ruby
99
+
100
+ DEPENDENCIES
101
+ activesupport (~> 4.0)
102
+ appraisal
103
+ bundler (~> 1.3)
104
+ capybara
105
+ rake
106
+ rspec
107
+ togostanza-server!
@@ -0,0 +1,43 @@
1
+ require 'sinatra/base'
2
+ require 'sinatra/reloader'
3
+ require 'haml'
4
+
5
+ module TogoStanza
6
+ class Application < Sinatra::Base
7
+ set :root, File.expand_path('../../..', __FILE__)
8
+ set :haml, escape_html: true
9
+
10
+ configure :development do
11
+ register Sinatra::Reloader
12
+ end
13
+
14
+ helpers do
15
+ def path(*paths)
16
+ prefix = env['SCRIPT_NAME']
17
+
18
+ [prefix, *paths].join('/').squeeze('/')
19
+ end
20
+ end
21
+
22
+ get '/' do
23
+ haml :index
24
+ end
25
+
26
+ get '/:id' do |id|
27
+ Stanza.find(id).new(params).render
28
+ end
29
+
30
+ get '/:id/resources/:resource_id' do |id, resource_id|
31
+ content_type :json
32
+
33
+ value = Stanza.find(id).new(params).resource(resource_id)
34
+ {resource_id => value}.to_json
35
+ end
36
+
37
+ get '/:id/help' do |id|
38
+ @stanza = Stanza.find(id).new
39
+
40
+ render :html, @stanza.help, layout_engine: :haml
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,81 @@
1
+ require 'thor'
2
+ require 'active_support/all'
3
+
4
+ module TogoStanza
5
+ module CLI
6
+ class ProviderGenerator < Thor::Group
7
+ include Thor::Actions
8
+
9
+ argument :name
10
+
11
+ def self.source_root
12
+ File.expand_path('../../../templates/provider', __FILE__)
13
+ end
14
+
15
+ def create_files
16
+ template 'Gemfile.erb', "#{name}/Gemfile"
17
+ template 'config.ru.erb', "#{name}/config.ru"
18
+ end
19
+
20
+ def init_repo
21
+ inside name do
22
+ run "bundle"
23
+ run "git init ."
24
+ run "git add -A"
25
+ end
26
+ end
27
+ end
28
+
29
+ class StanzaGenerator < Thor::Group
30
+ include Thor::Actions
31
+
32
+ argument :name
33
+
34
+ def self.source_root
35
+ File.expand_path('../../../templates/stanza', __FILE__)
36
+ end
37
+
38
+ def create_files
39
+ template 'Gemfile.erb', "#{file_name}/Gemfile"
40
+ template 'gemspec.erb', "#{file_name}/#{file_name}.gemspec"
41
+ template 'lib.rb.erb', "#{file_name}/lib/#{file_name}.rb"
42
+ template 'stanza.rb.erb', "#{file_name}/stanza.rb"
43
+ template 'template.hbs.erb', "#{file_name}/template.hbs"
44
+ template 'help.md.erb', "#{file_name}/help.md"
45
+ end
46
+
47
+ def inject_gem
48
+ append_to_file 'Gemfile', "gem '#{file_name}', path: './#{file_name}'"
49
+ end
50
+
51
+ private
52
+
53
+ def stanza_id
54
+ name.underscore.sub(/_stanza$/, '')
55
+ end
56
+
57
+ def file_name
58
+ stanza_id + '_stanza'
59
+ end
60
+
61
+ def class_name
62
+ file_name.classify
63
+ end
64
+
65
+ def title
66
+ stanza_id.titleize
67
+ end
68
+ end
69
+
70
+ class Stanza < Thor
71
+ register StanzaGenerator, 'new', 'new NAME', 'Creates a new stanza'
72
+ end
73
+
74
+ class Root < Thor
75
+ register ProviderGenerator, 'init', 'init NAME', 'Creates a new provider'
76
+
77
+ desc 'stanza [COMMAND]', ''
78
+ subcommand 'stanza', Stanza
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,39 @@
1
+ require 'redcarpet'
2
+
3
+ module TogoStanza
4
+ module Markdown
5
+ class << self
6
+ def render(source)
7
+ INSTANCE.render(source)
8
+ end
9
+ end
10
+
11
+ class Renderer < Redcarpet::Render::HTML
12
+ def table(header, body)
13
+ <<-HTML.strip_heredoc
14
+ <table class="table">
15
+ #{header}
16
+ #{body}
17
+ </table>
18
+ HTML
19
+ end
20
+ end
21
+
22
+ RENDERER = Renderer.new(
23
+ hard_wrap: true,
24
+ safe_links_only: true,
25
+ with_toc_data: true
26
+ )
27
+
28
+ INSTANCE = Redcarpet::Markdown.new(RENDERER,
29
+ autolink: true,
30
+ fenced_code_blocks: true,
31
+ lax_spacing: true,
32
+ no_intra_emphasis: true,
33
+ space_after_headers: true,
34
+ strikethrough: true,
35
+ superscript: false,
36
+ tables: true
37
+ )
38
+ end
39
+ end
@@ -0,0 +1,71 @@
1
+ require 'active_support/core_ext/module/delegation'
2
+ require 'flavour_saver'
3
+ require 'hashie/mash'
4
+
5
+ FS.register_helper :adjust_iframe_height_script do
6
+ <<-HTML.strip_heredoc.html_safe
7
+ <script>$(function() {
8
+ height = this.body.offsetHeight + 30;
9
+ parent.postMessage(JSON.stringify({height: height, id: name}), "*");
10
+ });</script>
11
+ HTML
12
+ end
13
+
14
+ module TogoStanza::Stanza
15
+ autoload :ExpressionMap, 'togostanza/stanza/expression_map'
16
+ autoload :Markdown, 'togostanza/stanza/markdown'
17
+ autoload :Querying, 'togostanza/stanza/querying'
18
+
19
+ class Base
20
+ extend ExpressionMap::Macro
21
+ include Querying
22
+
23
+ define_expression_map :properties
24
+ define_expression_map :resources
25
+
26
+ property :css_uri do |css_uri|
27
+ if css_uri
28
+ css_uri.split(',')
29
+ else
30
+ %w(
31
+ //cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.2.2/css/bootstrap.min.css
32
+ /stanza/assets/stanza.css
33
+ )
34
+ end
35
+ end
36
+
37
+ class_attribute :root
38
+
39
+ def self.id
40
+ to_s.underscore.sub(/_stanza$/, '')
41
+ end
42
+
43
+ delegate :id, to: 'self.class'
44
+
45
+ def initialize(params = {})
46
+ @params = params
47
+ end
48
+
49
+ attr_reader :params
50
+
51
+ def context
52
+ Hashie::Mash.new(properties.resolve_all_in_parallel(self, params))
53
+ end
54
+
55
+ def resource(name)
56
+ resources.resolve(self, name, params)
57
+ end
58
+
59
+ def render
60
+ path = File.join(root, 'template.hbs')
61
+
62
+ Tilt.new(path).render(context)
63
+ end
64
+
65
+ def help
66
+ path = File.join(root, 'help.md')
67
+
68
+ TogoStanza::Markdown.render(File.read(path))
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,44 @@
1
+ require 'active_support/core_ext/class/attribute'
2
+ require 'active_support/core_ext/string/inflections'
3
+ require 'active_support/hash_with_indifferent_access'
4
+ require 'parallel'
5
+
6
+ module TogoStanza::Stanza
7
+ class ExpressionMap < HashWithIndifferentAccess
8
+ module Macro
9
+ def define_expression_map(name)
10
+ class_attribute name
11
+
12
+ __send__ "#{name}=", ExpressionMap.new
13
+
14
+ define_singleton_method name.to_s.singularize do |key, val = nil, &block|
15
+ raise ArgumentError, 'You must specify exactly one of either a value or block' unless [val, block].one?(&:nil?)
16
+
17
+ __send__ "#{name}=", __send__(name).merge(key => block || val)
18
+ end
19
+ end
20
+ end
21
+
22
+ def resolve(context, key, params)
23
+ val = self[key]
24
+
25
+ return val unless val.respond_to?(:call)
26
+
27
+ args = val.parameters.reject {|type, _|
28
+ type == :block
29
+ }.map {|_, key|
30
+ params[key]
31
+ }
32
+
33
+ context.instance_exec(*args, &val)
34
+ end
35
+
36
+ def resolve_all_in_parallel(context, params)
37
+ Parallel.map(self, in_threads: 16) {|k, v|
38
+ [k, resolve(context, k, params)]
39
+ }.each_with_object({}) {|(k, v), memo|
40
+ memo[k] = v
41
+ }
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,37 @@
1
+ module TogoStanza::Stanza
2
+ module Markdown
3
+ class << self
4
+ def render(source)
5
+ INSTANCE.render(source)
6
+ end
7
+ end
8
+
9
+ class Renderer < Redcarpet::Render::HTML
10
+ def table(header, body)
11
+ <<-HTML.strip_heredoc
12
+ <table class="table">
13
+ #{header}
14
+ #{body}
15
+ </table>
16
+ HTML
17
+ end
18
+ end
19
+
20
+ RENDERER = Renderer.new(
21
+ hard_wrap: true,
22
+ safe_links_only: true,
23
+ with_toc_data: true
24
+ )
25
+
26
+ INSTANCE = Redcarpet::Markdown.new(RENDERER,
27
+ autolink: true,
28
+ fenced_code_blocks: true,
29
+ lax_spacing: true,
30
+ no_intra_emphasis: true,
31
+ space_after_headers: true,
32
+ strikethrough: true,
33
+ superscript: false,
34
+ tables: true
35
+ )
36
+ end
37
+ end