Skip to the content.
defmodule LiterateCompiler.Languages.Ruby do

Purpose

Processes Elixir files The atom Elixir is already used in the Elixir language - hence the module name

Public API

The fixed API could have been enforced as a behaviour but that’s a bit over the top


	def is_comment(line) do
		{newt, newl} = is_c(String.trim(line))
		case newt do
			{:code, :code} -> {newt, expand(line)}
			_              -> {newt, newl}
		end
	end

	def comment_level({:code,    _}), do: 0
	def comment_level({:comment, _}), do: 0
	def comment_level({:module,  _}), do: 1

	def get_css_ext, do: "ruby"

Private API

in the private function is_c take special notice of the doubled handling of comments


	defp is_c(<<"=begin",  r::binary>>), do: { {:module,  :open},  r}
	defp is_c(<<"## ",     r::binary>>), do: { {:comment, :open},  r}
	defp is_c(<<"##",      r::binary>>), do: { {:comment, :line},  r}
	defp is_c(<<"#jekyll", r::binary>>), do: { {:comment, :line},  r}
	defp is_c(<<"=end",    r::binary>>), do: { {:comment, :close}, r}
	defp is_c(c),                        do: { {:code,    :code},  c}

	defp expand(c) do
		newc = String.replace(c, "{ {", "{ {", [global: true])
		case Regex.match?(~r/{ {/, newc) do
			true  -> expand(newc)
			false -> newc
		end
	end

end