diff --git a/config.ru b/config.ru index 6bc7a3b..4f427e6 100644 --- a/config.ru +++ b/config.ru @@ -5,8 +5,8 @@ SERVE_DIR="/Users/madeline/Code/gemini-bridge-rack/gemini" class SkeksisApp def call(env) status = 200 - #headers = { "Content-Type" => "text/html" } - headers = {} + headers = { "content-type" => "text/html" } + #headers = {} body = resolve_path(SERVE_DIR + env['PATH_INFO']) [status, headers, body] @@ -18,8 +18,7 @@ class SkeksisApp elsif File.exist?(path) file = File.open(path, 'r') data = file.readlines - Skeksis::Parser.parse(data) - data + [Skeksis.htmlize(data)] else # path is invalid return nil end diff --git a/lib/skeksis.rb b/lib/skeksis.rb index abb9265..8f7b561 100644 --- a/lib/skeksis.rb +++ b/lib/skeksis.rb @@ -2,8 +2,15 @@ require_relative "skeksis/version" require_relative "skeksis/parser" +require_relative "skeksis/htmlize" module Skeksis class Error < StandardError; end # Your code goes here... + extend self + + def htmlize(data) + puts Skeksis::Parser.parse(data).htmlize + Skeksis::Parser.parse(data).htmlize + end end diff --git a/lib/skeksis/htmlize.rb b/lib/skeksis/htmlize.rb new file mode 100644 index 0000000..9fc981f --- /dev/null +++ b/lib/skeksis/htmlize.rb @@ -0,0 +1,60 @@ +module Skeksis + class IR + Header = <<~HTML + + + Gembridge + + + HTML + + Footer = <<~HTML + + + HTML + + def htmlize + build_html_doc + end + + private + def build_html_doc + content = self.parse_ir.join("\n") + Header + "#{content}\n" + Footer + end + + def parse_ir + html = self.map do |entry| + content = lambda { |entry| + unless entry[:content].nil? then return entry[:content][0] end + } + + text = content.call(entry) + + case entry[:type] + when :blank + "
" + when :header + level = entry[:level] + "#{text}" + when :list + # TODO: Does not handle lists properly, only one