forked from rouge-ruby/rouge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlex.rake
57 lines (48 loc) · 1.27 KB
/
lex.rake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
desc "Creates all necessary files for a new lexer"
task :lex, [:language] do |t, args|
language = args.language
sh "touch lib/rouge/demos/#{language}"
sh "touch spec/visual/samples/#{language}"
sh "echo \"#{lexer_template(language)}\" > lib/rouge/lexers/#{language}.rb"
sh "echo \"#{spec_template(language)}\" > spec/lexers/#{language}_spec.rb"
end
def lexer_template(language)
<<-LEX
module Rouge
module Lexers
class #{language.capitalize} < RegexLexer
desc '#{language}'
tag '#{language}'
aliases '#{language}'
filenames '*.???'
mimetypes 'text/x-#{language}', 'application/x-#{language}'
def self.analyze_text(text)
return 0
end
state :root do
end
end
end
end
LEX
end
def spec_template(language)
<<-SPEC
describe Rouge::Lexers::#{language.capitalize} do
let(:subject) { Rouge::Lexers::#{language.capitalize}.new }
describe 'guessing' do
include Support::Guessing
it 'guesses by filename' do
assert_guess :filename => 'foo.???'
end
it 'guesses by mimetype' do
assert_guess :mimetype => 'text/x-#{language}'
assert_guess :mimetype => 'application/x-#{language}'
end
it 'guesses by source' do
assert_guess :source => '????'
end
end
end
SPEC
end