class NishisukeBlogSyntax::Formatter::CodeFormatter

Constants

PARSE_REGEXP
SUBSTITUTE_REGEXP

Private Instance Methods

regexp() click to toggle source
# File lib/nishisuke_blog_syntax/formatter/code_formatter.rb, line 13
def regexp
  SUBSTITUTE_REGEXP
end
substitute(matched) click to toggle source
# File lib/nishisuke_blog_syntax/formatter/code_formatter.rb, line 17
def substitute(matched)
  content_str = matched.match(PARSE_REGEXP)[1]
  contents = content_str.split("\n")
  file_name = contents.shift
  contents.map! { |l| wrapped_line(l) }
  wrapped_content(contents.join('<br>'), file_name)
end
wrapped_content(content, file_name) click to toggle source
# File lib/nishisuke_blog_syntax/formatter/code_formatter.rb, line 29
      def wrapped_content(content, file_name)
        has_file_name = !file_name.gsub(/\s/, '').empty?

        html = <<~HTML.gsub("\n", '')
          <div class="shell mdc-elevation--z2">
          #{%Q(<span class="shell__file">#{file_name}</span>) if has_file_name}
          <pre class="shell__container">
          <code class="shell__code">
          #{content}
          </code>
          </pre>
          </div>
        HTML
      end
wrapped_line(txt) click to toggle source
# File lib/nishisuke_blog_syntax/formatter/code_formatter.rb, line 25
def wrapped_line(txt)
  %Q(<span class="shell__code-line">#{h(txt)}</span>)
end