nishisuke-blog-syntax 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.ruby-version +1 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/nishisuke_blog_syntax.rb +11 -0
- data/lib/nishisuke_blog_syntax/formatter.rb +7 -0
- data/lib/nishisuke_blog_syntax/formatter/code_formatter.rb +50 -0
- data/lib/nishisuke_blog_syntax/formatter/shell_formatter.rb +57 -0
- data/lib/nishisuke_blog_syntax/raw_text.rb +26 -0
- data/lib/nishisuke_blog_syntax/version.rb +3 -0
- data/nishisuke_blog_syntax.gemspec +36 -0
- metadata +103 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e13274afecedf181f356c27d03bcd5acc2fd3d3880544ad665ce0727939e096c
|
4
|
+
data.tar.gz: c0a48dde5caeba5685d43efeac06371716e5e95f1093cf0e82a6400f715f5d3e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1978a0a7788860b3e8252acc28fd4ece0840e00fb722d9a9bacc9ec90f5fa8b3a3de458100aa64a1293700d20cd7eaba1c2f3c7dfeb59a1631fd7b3e21bc25b3
|
7
|
+
data.tar.gz: b2702596de0dc94c44a2d0d4da68f20f080f5cc7860b30081ff4ec0dcabb53805805685cb4891b8dd62392620d123d1a2fee8ef51dc24b1a3d260997dfcef072
|
data/.gitignore
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.5.0
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 nishisuke
|
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,39 @@
|
|
1
|
+
# NishisukeBlogSyntax
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/nishisuke_blog_syntax`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'nishisuke_blog_syntax'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install nishisuke_blog_syntax
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
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).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/nishisuke_blog_syntax.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "nishisuke_blog_syntax"
|
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,50 @@
|
|
1
|
+
require 'nishisuke_blog_syntax/formatter'
|
2
|
+
require 'erb'
|
3
|
+
include ERB::Util
|
4
|
+
|
5
|
+
module NishisukeBlogSyntax
|
6
|
+
module Formatter
|
7
|
+
module CodeFormatter
|
8
|
+
REGEXP = /^SRC```(.*)SRC```$/m
|
9
|
+
|
10
|
+
class << self
|
11
|
+
def format(txt)
|
12
|
+
m = txt.match(REGEXP)
|
13
|
+
return txt if m.nil?
|
14
|
+
|
15
|
+
contents = m[1].split("\n")
|
16
|
+
|
17
|
+
file_name = contents.shift
|
18
|
+
|
19
|
+
content_str = contents.map { |l| wrapped_line(l) }.join('<br>')
|
20
|
+
html = wrapped_content(content_str, file_name)
|
21
|
+
|
22
|
+
txt.gsub(REGEXP, html)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def wrapped_line(txt)
|
28
|
+
%Q(<span class="shell__code-line">#{h(txt)}</span>)
|
29
|
+
end
|
30
|
+
|
31
|
+
def wrapped_content(content, file_name)
|
32
|
+
has_file_name = !file_name.gsub(/\s/, '').empty?
|
33
|
+
|
34
|
+
html = <<~HTML
|
35
|
+
<div class="shell mdc-elevation--z2">
|
36
|
+
#{%Q(<span class="shell__file">#{file_name}</span>) if has_file_name}
|
37
|
+
<pre class="shell__container">
|
38
|
+
<code class="shell__code">
|
39
|
+
#{content}
|
40
|
+
</code>
|
41
|
+
</pre>
|
42
|
+
</div>
|
43
|
+
HTML
|
44
|
+
|
45
|
+
html.gsub("\n", '')
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'nishisuke_blog_syntax/formatter'
|
2
|
+
require 'erb'
|
3
|
+
include ERB::Util
|
4
|
+
|
5
|
+
module NishisukeBlogSyntax
|
6
|
+
module Formatter
|
7
|
+
module ShellFormatter
|
8
|
+
REGEXP = /^SHELL```(.*)SHELL```$/m
|
9
|
+
INPUT_REGEXP = /\Ain: /
|
10
|
+
OUTPUT_REGEXP = /\Aout: /
|
11
|
+
|
12
|
+
class << self
|
13
|
+
def format(txt)
|
14
|
+
m = txt.match(REGEXP)
|
15
|
+
return txt if m.nil?
|
16
|
+
|
17
|
+
contents = m[1].split("\n")
|
18
|
+
|
19
|
+
file_name = contents.shift
|
20
|
+
|
21
|
+
content_str = contents.reject(&:empty?).map do |l|
|
22
|
+
wrapped_line(l)
|
23
|
+
end.join('<br>')
|
24
|
+
|
25
|
+
html = wrapped_content(content_str)
|
26
|
+
|
27
|
+
txt.gsub(REGEXP, html)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def wrapped_line(txt)
|
33
|
+
if m = txt.match(INPUT_REGEXP)
|
34
|
+
%Q(<kbd class="shell__input">#{h(m.post_match)}</kbd>)
|
35
|
+
elsif m = txt.match(OUTPUT_REGEXP)
|
36
|
+
%Q(<samp class="shell__output">#{h(m.post_match)}</samp>)
|
37
|
+
else
|
38
|
+
h(txt)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def wrapped_content(content)
|
43
|
+
html = <<~HTML
|
44
|
+
<div class="shell mdc-elevation--z2">
|
45
|
+
<pre class="shell__container">
|
46
|
+
<span class="shell__std">
|
47
|
+
#{content}
|
48
|
+
</span>
|
49
|
+
</pre>
|
50
|
+
</div>
|
51
|
+
HTML
|
52
|
+
html.gsub("\n", '')
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'nishisuke_blog_syntax/formatter'
|
2
|
+
|
3
|
+
module NishisukeBlogSyntax
|
4
|
+
class RawText
|
5
|
+
def initialize(text)
|
6
|
+
@text = text
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_html
|
10
|
+
self.class.html_formatters.inject(text.gsub(/\R/, "\n")) do |html, formatter|
|
11
|
+
formatter.format(html)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def self.html_formatters
|
18
|
+
@@formatters ||= [
|
19
|
+
Formatter::CodeFormatter,
|
20
|
+
Formatter::ShellFormatter,
|
21
|
+
]
|
22
|
+
end
|
23
|
+
|
24
|
+
attr_reader :text
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "nishisuke_blog_syntax/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'nishisuke-blog-syntax'
|
8
|
+
spec.version = NishisukeBlogSyntax::VERSION
|
9
|
+
spec.authors = ["nishisuke"]
|
10
|
+
spec.email = ["nishisuke13+git@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{This converts my own blog syntax to html.}
|
13
|
+
spec.description = %q{This converts my own blog syntax which looks like markdown to html.}
|
14
|
+
spec.homepage = "https://github.com/nishisuke/blog-syntax"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
+
"public gem pushes."
|
24
|
+
end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
28
|
+
end
|
29
|
+
spec.bindir = "exe"
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
34
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
35
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nishisuke-blog-syntax
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- nishisuke
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-01-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
description: This converts my own blog syntax which looks like markdown to html.
|
56
|
+
email:
|
57
|
+
- nishisuke13+git@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".ruby-version"
|
64
|
+
- ".travis.yml"
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- bin/console
|
70
|
+
- bin/setup
|
71
|
+
- lib/nishisuke_blog_syntax.rb
|
72
|
+
- lib/nishisuke_blog_syntax/formatter.rb
|
73
|
+
- lib/nishisuke_blog_syntax/formatter/code_formatter.rb
|
74
|
+
- lib/nishisuke_blog_syntax/formatter/shell_formatter.rb
|
75
|
+
- lib/nishisuke_blog_syntax/raw_text.rb
|
76
|
+
- lib/nishisuke_blog_syntax/version.rb
|
77
|
+
- nishisuke_blog_syntax.gemspec
|
78
|
+
homepage: https://github.com/nishisuke/blog-syntax
|
79
|
+
licenses:
|
80
|
+
- MIT
|
81
|
+
metadata:
|
82
|
+
allowed_push_host: https://rubygems.org
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 2.7.4
|
100
|
+
signing_key:
|
101
|
+
specification_version: 4
|
102
|
+
summary: This converts my own blog syntax to html.
|
103
|
+
test_files: []
|