faml 0.2.16 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +3 -3
- data/faml.gemspec +1 -0
- data/incompatibilities/README.md +4 -5
- data/incompatibilities/spec/render/attribute_spec.md +13 -219
- data/incompatibilities/spec/render/comment_spec.md +0 -23
- data/incompatibilities/spec/render/element_spec.md +1 -1
- data/incompatibilities/spec/render/newline_spec.md +0 -17
- data/lib/faml/cli.rb +1 -7
- data/lib/faml/compiler.rb +21 -23
- data/lib/faml/engine.rb +2 -2
- data/lib/faml/text_compiler.rb +2 -2
- data/lib/faml/version.rb +1 -1
- data/spec/rails/spec/requests/faml_spec.rb +2 -2
- data/spec/render/attribute_spec.rb +0 -114
- data/spec/render/comment_spec.rb +0 -11
- data/spec/render/doctype_spec.rb +0 -7
- data/spec/render/element_spec.rb +0 -57
- data/spec/render/filters_spec.rb +0 -4
- data/spec/render/plain_spec.rb +0 -7
- data/spec/render/sanitize_spec.rb +0 -7
- data/spec/render/script_spec.rb +0 -23
- data/spec/render/unescape_spec.rb +0 -7
- metadata +17 -15
- data/lib/faml/ast.rb +0 -116
- data/lib/faml/element_parser.rb +0 -235
- data/lib/faml/filter_parser.rb +0 -56
- data/lib/faml/indent_tracker.rb +0 -116
- data/lib/faml/line_parser.rb +0 -67
- data/lib/faml/parser.rb +0 -240
- data/lib/faml/parser_utils.rb +0 -17
- data/lib/faml/ruby_multiline.rb +0 -23
- data/lib/faml/script_parser.rb +0 -106
- data/lib/faml/syntax_error.rb +0 -6
- data/spec/render/indent_spec.rb +0 -47
data/lib/faml/parser_utils.rb
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
module Faml
|
|
2
|
-
module ParserUtils
|
|
3
|
-
module_function
|
|
4
|
-
|
|
5
|
-
def balance(scanner, start, finish, depth = 1)
|
|
6
|
-
re = /(#{Regexp.escape(start)}|#{Regexp.escape(finish)})/
|
|
7
|
-
while depth > 0 && scanner.scan_until(re)
|
|
8
|
-
if scanner.matched == start
|
|
9
|
-
depth += 1
|
|
10
|
-
else
|
|
11
|
-
depth -= 1
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
depth
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
data/lib/faml/ruby_multiline.rb
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
module Faml
|
|
2
|
-
module RubyMultiline
|
|
3
|
-
def self.read(line_parser, current_text)
|
|
4
|
-
buf = []
|
|
5
|
-
while is_ruby_multiline?(current_text)
|
|
6
|
-
current_text = line_parser.next_line
|
|
7
|
-
buf << current_text
|
|
8
|
-
end
|
|
9
|
-
buf
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
# `text' is a Ruby multiline block if it:
|
|
13
|
-
# - ends with a comma
|
|
14
|
-
# - but not "?," which is a character literal
|
|
15
|
-
# (however, "x?," is a method call and not a literal)
|
|
16
|
-
# - and not "?\," which is a character literal
|
|
17
|
-
def self.is_ruby_multiline?(text)
|
|
18
|
-
text && text.length > 1 && text[-1] == ?, &&
|
|
19
|
-
!((text[-3, 2] =~ /\W\?/) || text[-3, 2] == "?\\")
|
|
20
|
-
end
|
|
21
|
-
private_class_method :is_ruby_multiline?
|
|
22
|
-
end
|
|
23
|
-
end
|
data/lib/faml/script_parser.rb
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
require 'faml/ast'
|
|
2
|
-
require 'faml/ruby_multiline'
|
|
3
|
-
require 'faml/syntax_error'
|
|
4
|
-
|
|
5
|
-
module Faml
|
|
6
|
-
class ScriptParser
|
|
7
|
-
def initialize(line_parser)
|
|
8
|
-
@line_parser = line_parser
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def parse(text)
|
|
12
|
-
case text[0]
|
|
13
|
-
when '=', '~'
|
|
14
|
-
parse_script(text)
|
|
15
|
-
when '&'
|
|
16
|
-
parse_sanitized(text)
|
|
17
|
-
when '!'
|
|
18
|
-
parse_unescape(text)
|
|
19
|
-
else
|
|
20
|
-
parse_text(text)
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
private
|
|
25
|
-
|
|
26
|
-
def parse_script(text)
|
|
27
|
-
if text[1] == '='
|
|
28
|
-
create_node(Ast::Text) { |t| t.text = text[2 .. -1].strip }
|
|
29
|
-
else
|
|
30
|
-
node = create_node(Ast::Script)
|
|
31
|
-
script = text[1 .. -1].lstrip
|
|
32
|
-
if script.empty?
|
|
33
|
-
syntax_error!('No Ruby code to evaluate')
|
|
34
|
-
end
|
|
35
|
-
node.script = [script, *RubyMultiline.read(@line_parser, script)].join("\n")
|
|
36
|
-
node
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def parse_sanitized(text)
|
|
41
|
-
case
|
|
42
|
-
when text.start_with?('&==')
|
|
43
|
-
create_node(Ast::Text) { |t| t.text = text[3 .. -1].lstrip }
|
|
44
|
-
when text[1] == '=' || text[1] == '~'
|
|
45
|
-
node = create_node(Ast::Script)
|
|
46
|
-
script = text[2 .. -1].lstrip
|
|
47
|
-
if script.empty?
|
|
48
|
-
syntax_error!('No Ruby code to evaluate')
|
|
49
|
-
end
|
|
50
|
-
node.script = [script, *RubyMultiline.read(@line_parser, script)].join("\n")
|
|
51
|
-
node.preserve = text[1] == '~'
|
|
52
|
-
node
|
|
53
|
-
else
|
|
54
|
-
create_node(Ast::Text) { |t| t.text = text[1 .. -1].strip }
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
def parse_unescape(text)
|
|
59
|
-
case
|
|
60
|
-
when text.start_with?('!==')
|
|
61
|
-
create_node(Ast::Text) do |t|
|
|
62
|
-
t.text = text[3 .. -1].lstrip
|
|
63
|
-
t.escape_html = false
|
|
64
|
-
end
|
|
65
|
-
when text[1] == '=' || text[1] == '~'
|
|
66
|
-
node = create_node(Ast::Script)
|
|
67
|
-
node.escape_html = false
|
|
68
|
-
script = text[2 .. -1].lstrip
|
|
69
|
-
if script.empty?
|
|
70
|
-
syntax_error!('No Ruby code to evaluate')
|
|
71
|
-
end
|
|
72
|
-
node.script = [script, *RubyMultiline.read(@line_parser, script)].join("\n")
|
|
73
|
-
node.preserve = text[1] == '~'
|
|
74
|
-
node
|
|
75
|
-
else
|
|
76
|
-
create_node(Ast::Text) do |t|
|
|
77
|
-
t.text = text[1 .. -1].lstrip
|
|
78
|
-
t.escape_html = false
|
|
79
|
-
end
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
def parse_text(text)
|
|
84
|
-
text = text.lstrip
|
|
85
|
-
if text.empty?
|
|
86
|
-
nil
|
|
87
|
-
else
|
|
88
|
-
create_node(Ast::Text) { |t| t.text = text }
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
def syntax_error!(message)
|
|
93
|
-
raise SyntaxError.new(message, @line_parser.lineno)
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
def create_node(klass, &block)
|
|
97
|
-
klass.new.tap do |node|
|
|
98
|
-
node.filename = @line_parser.filename
|
|
99
|
-
node.lineno = @line_parser.lineno
|
|
100
|
-
if block
|
|
101
|
-
block.call(node)
|
|
102
|
-
end
|
|
103
|
-
end
|
|
104
|
-
end
|
|
105
|
-
end
|
|
106
|
-
end
|
data/lib/faml/syntax_error.rb
DELETED
data/spec/render/indent_spec.rb
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
RSpec.describe 'Indent', type: :render do
|
|
4
|
-
it 'raises error if indent is wrong' do
|
|
5
|
-
expect { render_string(<<HAML) }.to raise_error(Faml::IndentTracker::IndentMismatch) { |e|
|
|
6
|
-
%div
|
|
7
|
-
%div
|
|
8
|
-
%div
|
|
9
|
-
%div
|
|
10
|
-
HAML
|
|
11
|
-
expect(e.current_level).to eq(2)
|
|
12
|
-
expect(e.indent_levels).to eq([0])
|
|
13
|
-
expect(e.lineno).to eq(4)
|
|
14
|
-
}
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
it 'raises error if the current indent is deeper than the previous one' do
|
|
18
|
-
expect { render_string(<<HAML) }.to raise_error(Faml::IndentTracker::InconsistentIndent) { |e|
|
|
19
|
-
%div
|
|
20
|
-
%div
|
|
21
|
-
%div
|
|
22
|
-
HAML
|
|
23
|
-
expect(e.previous_size).to eq(2)
|
|
24
|
-
expect(e.current_size).to eq(4)
|
|
25
|
-
expect(e.lineno).to eq(3)
|
|
26
|
-
}
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
it 'raises error if the current indent is shallower than the previous one' do
|
|
30
|
-
expect { render_string(<<HAML) }.to raise_error(Faml::IndentTracker::InconsistentIndent) { |e|
|
|
31
|
-
%div
|
|
32
|
-
%div
|
|
33
|
-
%div
|
|
34
|
-
HAML
|
|
35
|
-
expect(e.previous_size).to eq(4)
|
|
36
|
-
expect(e.current_size).to eq(2)
|
|
37
|
-
expect(e.lineno).to eq(3)
|
|
38
|
-
}
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
it 'raises error if indented with hard tabs' do
|
|
42
|
-
expect { render_string(<<HAML) }.to raise_error(Faml::IndentTracker::HardTabNotAllowed)
|
|
43
|
-
%p
|
|
44
|
-
%a
|
|
45
|
-
HAML
|
|
46
|
-
end
|
|
47
|
-
end
|