diff --git a/shard.yml b/shard.yml index 2847f3b..946fac5 100644 --- a/shard.yml +++ b/shard.yml @@ -13,6 +13,7 @@ dependencies: github: crystal-china/base58.cr sixteen: github: ralsina/sixteen + branch: main crystal: ">= 1.13.0" diff --git a/src/constants.cr b/src/constants.cr index 2479df9..8657359 100644 --- a/src/constants.cr +++ b/src/constants.cr @@ -1,5 +1,6 @@ module Tartrazine Abbreviations = { + "Background" => "b", "Text" => "t", "CommentSingle" => "cs", "CommentSpecial" => "cs", diff --git a/src/formatter.cr b/src/formatter.cr index 6e92e0b..3c3d572 100644 --- a/src/formatter.cr +++ b/src/formatter.cr @@ -1,4 +1,4 @@ -require "./constantes.cr" +require "./constants.cr" require "./styles.cr" require "./tartrazine.cr" @@ -15,7 +15,7 @@ module Tartrazine def get_style_defs(theme : Theme) : String output = String.build do |outp| theme.styles.each do |token, style| - outp << ".#{token} {" + outp << ".#{get_css_class(token, theme)} {" # These are set or nil outp << "color: #{style.color};" if style.color outp << "background-color: #{style.background};" if style.background @@ -43,7 +43,7 @@ module Tartrazine outp << "
" - outp << ""
+ outp << ""
lexer.tokenize(text).each do |token|
fragment = "#{token[:value]}"
outp << fragment
@@ -55,16 +55,15 @@ module Tartrazine
# Given a token type, return the CSS class to use.
def get_css_class(token, theme)
- token = Abbreviations[token]
- return token if theme.styles.has_key?(token)
+ return Abbreviations[token] if theme.styles.has_key?(token)
# Themes don't contain information for each specific
# token type. However, they may contain information
# for a parent style. Worst case, we go to the root
# (Background) style.
- theme.style_parents(token).reverse.find { |parent|
+ Abbreviations[theme.style_parents(token).reverse.find { |parent|
theme.styles.has_key?(parent)
- }
+ }]
end
end
end
diff --git a/src/main.cr b/src/main.cr
index 075667a..99cf49e 100644
--- a/src/main.cr
+++ b/src/main.cr
@@ -1,4 +1,4 @@
-require "./**"
+require "./**"
lexer = Tartrazine.lexer("crystal")
theme = Tartrazine.theme(ARGV[1])
diff --git a/src/styles.cr b/src/styles.cr
index 0823e4f..7d7dfc8 100644
--- a/src/styles.cr
+++ b/src/styles.cr
@@ -29,7 +29,7 @@ module Tartrazine
# anything
property? complete : Bool = false
- def initialize(@color=nil, @background=nil, @border=nil, @bold=nil, @italic=nil, @underline=nil)
+ def initialize(@color = nil, @background = nil, @border = nil, @bold = nil, @italic = nil, @underline = nil)
end
macro merge_prop(prop)
@@ -95,8 +95,8 @@ module Tartrazine
theme.styles["Text"] = Style.new(color: t.palette["base05"])
theme.styles["Error"] = Style.new(color: t.palette["base08"])
theme.styles["Comment"] = Style.new(color: t.palette["base03"])
- theme.styles["CommentPreProc"] = Style.new(color: t.palette["base0F"])
- theme.styles["CommentPreProcFile"] = Style.new(color: t.palette["base0B"])
+ theme.styles["CommentPreproc"] = Style.new(color: t.palette["base0F"])
+ theme.styles["CommentPreprocFile"] = Style.new(color: t.palette["base0B"])
theme.styles["Keyword"] = Style.new(color: t.palette["base0E"])
theme.styles["KeywordType"] = Style.new(color: t.palette["base08"])
theme.styles["NameAttribute"] = Style.new(color: t.palette["base0D"])
@@ -110,14 +110,14 @@ module Tartrazine
theme.styles["NameTag"] = Style.new(color: t.palette["base0E"])
theme.styles["NameVariable"] = Style.new(color: t.palette["base0D"])
theme.styles["NameVariableInstance"] = Style.new(color: t.palette["base08"])
- theme.styles["Number"] = Style.new(color: t.palette["base09"])
+ theme.styles["LiteralNumber"] = Style.new(color: t.palette["base09"])
theme.styles["Operator"] = Style.new(color: t.palette["base0C"])
theme.styles["OperatorWord"] = Style.new(color: t.palette["base0E"])
theme.styles["Literal"] = Style.new(color: t.palette["base0B"])
- theme.styles["String"] = Style.new(color: t.palette["base0B"])
- theme.styles["StringInterpol"] = Style.new(color: t.palette["base0F"])
- theme.styles["StringRegex"] = Style.new(color: t.palette["base0C"])
- theme.styles["StringSymbol"] = Style.new(color: t.palette["base09"])
+ theme.styles["LiteralString"] = Style.new(color: t.palette["base0B"])
+ theme.styles["LiteralStringInterpol"] = Style.new(color: t.palette["base0F"])
+ theme.styles["LiteralStringRegex"] = Style.new(color: t.palette["base0C"])
+ theme.styles["LiteralStringSymbol"] = Style.new(color: t.palette["base09"])
theme
end