haml_parser 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9b06a7a145edcaee2bae05feafbd265c680a8e54
4
- data.tar.gz: 70e85219456f494d6d3d0f8f337727ecbbede342
3
+ metadata.gz: 7419fb3e0cafc26ec4b25af1bbc614a22befe953
4
+ data.tar.gz: 8446c4f6c9535169f187f482ed012af5c324ce4b
5
5
  SHA512:
6
- metadata.gz: 88b446fd2edd5507ec973dd5926fc8b12b118c4e07f30bcb93a080d546905095ff87c08e683535d648b8801452d06188e1b9a41685911e356e2215a1545c206d
7
- data.tar.gz: 65583c26a71fe5890e5f78dc9f885b17b9c5c169f8cb6ff95767971c50e82b7d3f8ae2f64f3a967b1612216db5590d7bdfe140fd5189d1fd22f52ae9b135d961
6
+ metadata.gz: 6b59ff50da183f5ca981d745d38d2224c438374fc9e99acfd8d7e231541056292c54648e5d4682781c6bfa5bdbf0464227a4969c96ca130f6f872a809dbf52de
7
+ data.tar.gz: ec69c79bbdca9b31d33350e662562e1fa7ad8362fe3a0e077500aa600cbe7782fd8f4be11df655b562b14906e4cdbf7d73ac6de325b0e9adc3ee9c58cc01a559
@@ -1,5 +1,9 @@
1
1
  inherit_from: .rubocop_todo.yml
2
2
 
3
+ AllCops:
4
+ DisplayCopNames: true
5
+ TargetRubyVersion: 2.3
6
+
3
7
  Style/BarePercentLiterals:
4
8
  EnforcedStyle: percent_q
5
9
 
@@ -35,7 +39,10 @@ Style/Tab:
35
39
  Exclude:
36
40
  - 'spec/indent_spec.rb'
37
41
 
38
- Style/TrailingComma:
42
+ Style/TrailingCommaInLiteral:
43
+ Enabled: false
44
+
45
+ Style/TrailingCommaInArguments:
39
46
  Enabled: false
40
47
 
41
48
  Style/TrailingWhitespace:
@@ -44,3 +51,6 @@ Style/TrailingWhitespace:
44
51
 
45
52
  Style/UnneededPercentQ:
46
53
  Enabled: false # buggy
54
+
55
+ Performance/RedundantBlockCall:
56
+ Enabled: false
@@ -1,9 +1,9 @@
1
1
  language: ruby
2
2
  sudo: false
3
3
  rvm:
4
- - 2.0.0
5
- - 2.1
6
- - 2.2
4
+ - 2.1.10
5
+ - 2.2.5
6
+ - 2.3.1
7
7
  - ruby-head
8
8
  after_script:
9
9
  - bundle exec rake benchmark
@@ -1,3 +1,6 @@
1
+ # 0.4.1 (2016-07-02)
2
+ - Raise error when the first line has indentation
3
+
1
4
  # 0.4.0 (2015-11-21)
2
5
  - Old attributes and new attributes are no longer merged
3
6
  - `Ast::Element#attributes` is left for compatibility
data/Gemfile CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  source 'https://rubygems.org'
2
3
 
3
4
  # Specify your gem's dependencies in haml_parser.gemspec
data/Rakefile CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'bundler/gem_tasks'
2
3
 
3
4
  task :default => [:spec, :rubocop]
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'bundler/setup'
4
5
  require 'haml_parser'
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
  require 'haml_parser/cli'
3
4
 
4
5
  HamlParser::CLI.start(ARGV)
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
2
3
  lib = File.expand_path('../lib', __FILE__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'haml_parser/version'
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require_relative 'haml_parser/version'
2
3
 
3
4
  module HamlParser
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module HamlParser
2
3
  module Ast
3
4
  module HasChildren
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'optparse'
2
3
  require_relative 'version'
3
4
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'strscan'
2
3
  require_relative 'ast'
3
4
  require_relative 'error'
@@ -99,12 +100,10 @@ module HamlParser
99
100
  if depth == 0
100
101
  attr = s.pre_match + s.matched
101
102
  return [attr[1, attr.size - 2], s.rest]
103
+ elsif /,\s*\z/ === text && @line_parser.has_next?
104
+ text << "\n" << @line_parser.next_line
102
105
  else
103
- if /,\s*\z/ === text && @line_parser.has_next?
104
- text << "\n" << @line_parser.next_line
105
- else
106
- syntax_error!('Unmatched brace')
107
- end
106
+ syntax_error!('Unmatched brace')
108
107
  end
109
108
  end
110
109
  end
@@ -120,12 +119,10 @@ module HamlParser
120
119
  if depth == 0
121
120
  t = s.string.byteslice(pre_pos...s.pos - 1)
122
121
  return [parse_new_attribute_list(t), s.rest]
122
+ elsif @line_parser.has_next?
123
+ text << "\n" << @line_parser.next_line
123
124
  else
124
- if @line_parser.has_next?
125
- text << "\n" << @line_parser.next_line
126
- else
127
- syntax_error!('Unmatched paren')
128
- end
125
+ syntax_error!('Unmatched paren')
129
126
  end
130
127
  end
131
128
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module HamlParser
2
3
  class Error < StandardError
3
4
  attr_accessor :lineno
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require_relative 'ast'
2
3
 
3
4
  module HamlParser
@@ -35,15 +36,13 @@ module HamlParser
35
36
  @ast = nil
36
37
  return ast
37
38
  end
39
+ elsif indent_level > @indent_tracker.current_level
40
+ # Start filter
41
+ @indent_level = indent_level
38
42
  else
39
- if indent_level > @indent_tracker.current_level
40
- # Start filter
41
- @indent_level = indent_level
42
- else
43
- # Empty filter
44
- @ast = nil
45
- return nil
46
- end
43
+ # Empty filter
44
+ @ast = nil
45
+ return nil
47
46
  end
48
47
 
49
48
  text = line[@indent_level..-1]
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require_relative 'error'
2
3
 
3
4
  module HamlParser
@@ -36,7 +37,7 @@ module HamlParser
36
37
  end
37
38
 
38
39
  def process(line, lineno)
39
- if line =~ /\A\t/
40
+ if line.start_with?("\t")
40
41
  raise HardTabNotAllowed.new(lineno)
41
42
  end
42
43
  indent, text = split(line)
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module HamlParser
2
3
  class LineParser
3
4
  attr_reader :filename, :lineno
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require_relative 'ast'
2
3
  require_relative 'element_parser'
3
4
  require_relative 'error'
@@ -180,6 +181,8 @@ module HamlParser
180
181
  syntax_error!('nesting within plain text is illegal')
181
182
  when Ast::Doctype
182
183
  syntax_error!('nesting within a header command is illegal')
184
+ when nil
185
+ syntax_error!('Indenting at the beginning of the document is illegal')
183
186
  end
184
187
  @ast.children = empty_lines
185
188
  if @ast.is_a?(Ast::Element) && @ast.self_closing
@@ -202,8 +205,8 @@ module HamlParser
202
205
  nil
203
206
  end
204
207
 
205
- MID_BLOCK_KEYWORDS = %w[else elsif rescue ensure end when]
206
- START_BLOCK_KEYWORDS = %w[if begin case unless]
208
+ MID_BLOCK_KEYWORDS = %w[else elsif rescue ensure end when].freeze
209
+ START_BLOCK_KEYWORDS = %w[if begin case unless].freeze
207
210
  # Try to parse assignments to block starters as best as possible
208
211
  START_BLOCK_KEYWORD_REGEX = /(?:\w+(?:,\s*\w+)*\s*=\s*)?(#{Regexp.union(START_BLOCK_KEYWORDS)})/
209
212
  BLOCK_KEYWORD_REGEX = /^-?\s*(?:(#{Regexp.union(MID_BLOCK_KEYWORDS)})|#{START_BLOCK_KEYWORD_REGEX.source})\b/
@@ -224,7 +227,7 @@ module HamlParser
224
227
  node.filename = @line_parser.filename
225
228
  node.lineno = @line_parser.lineno
226
229
  if block
227
- block.call(node)
230
+ yield(node)
228
231
  end
229
232
  end
230
233
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module HamlParser
2
3
  module RubyMultiline
3
4
  def self.read(line_parser, current_text)
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require_relative 'ast'
2
3
  require_relative 'error'
3
4
  require_relative 'ruby_multiline'
@@ -39,10 +40,9 @@ module HamlParser
39
40
  end
40
41
 
41
42
  def parse_sanitized(text)
42
- case
43
- when text.start_with?('&==')
43
+ if text.start_with?('&==')
44
44
  create_node(Ast::Text) { |t| t.text = text[3..-1].lstrip }
45
- when text[1] == '=' || text[1] == '~'
45
+ elsif text[1] == '=' || text[1] == '~'
46
46
  node = create_node(Ast::Script)
47
47
  script = text[2..-1].lstrip
48
48
  if script.empty?
@@ -57,13 +57,12 @@ module HamlParser
57
57
  end
58
58
 
59
59
  def parse_unescape(text)
60
- case
61
- when text.start_with?('!==')
60
+ if text.start_with?('!==')
62
61
  create_node(Ast::Text) do |t|
63
62
  t.text = text[3..-1].lstrip
64
63
  t.escape_html = false
65
64
  end
66
- when text[1] == '=' || text[1] == '~'
65
+ elsif text[1] == '=' || text[1] == '~'
67
66
  node = create_node(Ast::Script)
68
67
  node.escape_html = false
69
68
  script = text[2..-1].lstrip
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module HamlParser
2
3
  module Utils
3
4
  module_function
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module HamlParser
2
- VERSION = '0.4.0'
3
+ VERSION = '0.4.1'
3
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: haml_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kohei Suzuki
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-11-21 00:00:00.000000000 Z
11
+ date: 2016-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: benchmark-ips
@@ -191,7 +191,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
191
191
  version: '0'
192
192
  requirements: []
193
193
  rubyforge_project:
194
- rubygems_version: 2.5.0
194
+ rubygems_version: 2.6.6
195
195
  signing_key:
196
196
  specification_version: 4
197
197
  summary: Parser of Haml template language