jeanny 0.98 → 0.99

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.
Files changed (3) hide show
  1. data/lib/jeanny/engine.rb +21 -82
  2. data/lib/jeanny/extend.rb +1 -1
  3. metadata +1 -1
data/lib/jeanny/engine.rb CHANGED
@@ -330,17 +330,11 @@ module Jeanny
330
330
 
331
331
  def replace classes
332
332
 
333
- # Вырезаем экспрешены
334
- expression_list = []
335
- @code.replace_expressions! do |expression|
336
- # и заменяем в них классы как в js
337
- expression_list << JSCode.new(expression).replace(classes)
338
- "_ololo_#{expression_list.length}_ololo_"
339
- end
340
-
341
- # Вставляем экспрешены с замененными классами обратно
342
- expression_list.each_with_index do |expression, index|
343
- @code.gsub! /_ololo_#{index + 1}_ololo_/, expression
333
+ # Заменяем в экспрешенах
334
+ @code.each_expression do |expression|
335
+ @code.gsub! expression do |a|
336
+ JSCode.new(expression).replace(classes)
337
+ end
344
338
  end
345
339
 
346
340
  @code.gsub!(/\[class\^=(.*?)\]/) do |class_name|
@@ -433,91 +427,36 @@ module Jeanny
433
427
  class TT2Template < HTMLCode
434
428
 
435
429
  def replace classes
436
-
437
- tags = []
438
- @code.gsub! /\[%(.*?)%\]/ do |tag|
439
- tags << $1
440
-
441
- "__tt2-tag__#{tags.length}__"
430
+
431
+ tags = Array.new
432
+ mark = self.object_id
433
+
434
+ @code.gsub! /\[%(.*?)%\]/m do |tag|
435
+ tags.push tag and "#{mark}:#{tags.length - 1}:"
442
436
  end
443
437
 
444
438
  super classes
445
-
446
- tags.map! do |tag|
447
-
448
- # Пропускаем конструкции в которых точно ничего нет
449
- unless tag =~ /^\s*(#|BLOCK|PROCESS|INCLUDE|INSERT|END\s*$|ELSE\s*$)/im
450
- each_string :in => tag do |string|
451
- unless string =~ /\.(tt2|css|js|png|jpg|gif)\s*$/
452
- string_after = string.dup
453
- classes.each do |full_class, short_class|
454
- while (pos = string_after =~ /#{full_class}(?=[^a-z0-9\-_\.]|$)/)
455
- string_after[pos, full_class.length] = short_class
456
- end
457
- end
458
- tag = tag.sub string, string_after
439
+
440
+ classes.each do |full_class, short_class|
441
+ tags.map! do |tag|
442
+ tag.gsub /((BLOCK|PROCESS|INCLUDE|INSERT)\s+('|").*?[^\\]\3)|(('|").*?[^\\]\5)/ do |string|
443
+ unless $5.nil?
444
+ string.gsub /#{full_class}(?=[\s"']|$|\\["'])/, short_class
445
+ else
446
+ string
459
447
  end
460
- tag
461
448
  end
462
449
  end
463
- tag
464
450
  end
465
451
 
466
- tags.each_with_index do |tag, index|
467
- @code.gsub!(/__tt2-tag__#{index + 1}__/, "[%#{tag}%]")
452
+ tags.select.with_index do |tag, index|
453
+ @code.gsub! "#{mark}:#{index}:", tag
468
454
  end
469
455
 
470
456
  @code
471
457
 
472
458
  end
473
459
 
474
- private
475
-
476
- def each_string args = { }
477
-
478
- char = ''
479
- last_char = ''
480
- start_char = ''
481
-
482
- value = ''
483
- status = :in_code
484
- scanner = StringScanner.new args[:in].dup || ''
485
-
486
- until scanner.eos?
487
-
488
- scanner.getch or next
489
- char = scanner.matched
490
-
491
- case status
492
-
493
- when :in_code
494
- # Если мы в коде, а текущий символ один из тех что нам надо
495
- # значит запоминаем, этот символ и переходим в режим "в строке"
496
- if %w(" ').include? char
497
- start_char = char
498
- status = :in_string
499
- end
500
-
501
- when :in_string
502
- # Если мы в строке, текущий символ такой же как и начальный,
503
- # а предыдущий не экранирует его, значит строка законченна.
504
- # Переходим в режим "в коде"
505
- if char.eql? start_char and not last_char.eql? '\\'
506
- yield value if block_given?
507
- status, start_char, value = :in_code, '', ''
508
- # Иначе, прибавляем текущий символ к уже полученной строке
509
- else
510
- value = value + char
511
- end
512
-
513
- end
514
-
515
- last_char = char unless char.nil? or char =~ /\s/
516
-
517
- end
518
-
519
- end
520
-
521
460
  end
522
461
 
523
462
  class PlainCode < Code
data/lib/jeanny/extend.rb CHANGED
@@ -175,4 +175,4 @@ module Jeanny
175
175
 
176
176
  %w(FileNotFound CompareFileFormatError ClassesNotFound).each { |error| eval "class Jeanny#{error} < RuntimeError; end" }
177
177
 
178
- end
178
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jeanny
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.98"
4
+ version: "0.99"
5
5
  platform: ruby
6
6
  authors:
7
7
  - gfranco