Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tokenization of compact Ruby class names #1470

Merged
merged 1 commit into from
Mar 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/rouge/lexers/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,8 @@ def self.detect?(text)

state :classname do
rule %r/\s+/, Text
rule %r/\w+(::\w+)+/, Name::Class

rule %r/\(/ do
token Punctuation
push :defexpr
Expand Down
39 changes: 39 additions & 0 deletions spec/visual/samples/ruby
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,45 @@ class Ipsum < Lorem
end
end

########
# Various types of class definitions
########

# Singleton class definition
module Table
module Row
DEFAULTS = { cell_width: 80, cell_height: 60 }

class << self
def styles hsh
hsh.merge DEFAULTS
end
end
end
end

# Nested class name
module Table
module Row
class Cell < Table::Block
WIDTH = TABLE::ROW::styles[:cell_width]

def text string, width = WIDTH
string.center width
end
end
end
end

# Compact class name
class Table::Row::Cell < Table::Block
WIDTH = TABLE::ROW::styles[:cell_width]

def text string, width = WIDTH
string.center width
end
end

########
# The popular . :bow:
########
Expand Down