uv 0.0.7.2 → 0.0.7.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,38 +1,47 @@
1
1
  module Uv
2
2
 
3
3
  def Uv.find_syntaxes_by_ext(ext)
4
- syntaxes = []
5
- if !@syntaxes.key?(ext)
6
- @syntaxes.each do |syntax_name, syntax_node|
7
- syntaxes << syntax_node if syntax_node.fileTypes && syntax_node.fileTypes.include?(ext)
8
- end
9
- filename = File.join(@syntax_path, "#{ext}.syntax")
10
- syntaxes << Textpow::SyntaxNode.load(filename) if File.exist?(filename)
11
- else
12
- syntaxes << @syntaxes[ext]
13
- end
14
- syntaxes
4
+ return [load_syntax(ext)] if @syntaxes.key?(ext)
5
+ puts "No syntax found... loading all syntaxes (including all syntax.fileTypes)" if @debug
6
+ load_all_syntaxes
7
+ return [load_syntax(ext)] if @syntaxes.key?(ext)
8
+ []
15
9
  end
16
10
 
17
11
  def Uv.find_syntaxes_by_first_line(first_line)
18
- syntaxes = []
19
- @syntaxes.each do |syntax_name, syntax_node|
20
- syntaxes << syntax_node if syntax_node.firstLineMatch && syntax_node.firstLineMatch =~ first_line
12
+ return nil if first_line = ''
13
+ puts "Searching syntaxes by first line..." if @debug
14
+ @syntaxes.values.compact.each do |syntax_node|
15
+ return syntax_node if syntax_node && syntax_node.firstLineMatch && syntax_node.firstLineMatch =~ first_line
21
16
  end
22
- syntaxes
23
17
  end
24
18
 
25
- def Uv.find_syntaxes(extensions=[], first_line='')
26
- init_syntaxes unless @syntaxes
27
- syntaxes = []
28
- extensions.each do |ext|
29
- syntaxes += find_syntaxes_by_ext(ext)
19
+ def Uv.find_syntaxes(extensions=[], first_line='', slow_search=false)
20
+ puts "Finding syntaxes for: Extensions: [#{extensions.join(', ')}], First Line: '#{first_line.inspect}'" if @debug
21
+ init_syntaxes if @syntaxes.empty?
22
+ syntaxes = []; extensions.delete(''); extensions.compact!
23
+ case slow_search
24
+ when false
25
+ syntaxes << load_syntax(extensions.first) unless extensions.empty?
26
+ when true
27
+ syntaxes += extensions.collect {|ext| find_syntaxes_by_ext(ext) }.flatten.compact
28
+ syntaxes += find_syntaxes_by_first_line(first_line) if syntaxes.empty?
30
29
  end
31
- syntaxes += find_syntaxes_by_first_line(first_line)
30
+ syntaxes.compact!
31
+ puts "Syntaxes found: [#{syntaxes.collect(&:name).join(', ')}]" if @debug and not syntaxes.empty?
32
+ puts "Uv Error: No syntax match found for '#{extensions.join(', ')}', defaulting to 'plain_text' syntax" if @debug and syntaxes.empty?
32
33
  syntaxes
33
34
  end
34
35
 
35
36
 
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
36
45
  # Returns the Textpow::SyntaxNode for this syntax;
37
46
  # @raise ArgumentError if no syntax is found
38
47
  # Ex: syntax_node_for('ruby') => Textpow::SyntaxNode.load('ruby.syntax')
@@ -0,0 +1,51 @@
1
+ module Uv
2
+
3
+ # Loads @syntaxes with all the syntax names.
4
+ # DOES NOT load the syntax files into TextPow
5
+ def Uv.init_syntaxes
6
+ puts "Uv: Finding all syntax names..." if @debug
7
+ syntax_names.each do |syntax_name|
8
+ puts "Uv: Setting @syntax[#{syntax_name}]" if @debug and !@syntaxes.key?(syntax_name)
9
+ @syntaxes[syntax_name] = nil unless @syntaxes.key?(syntax_name)
10
+ end
11
+ @syntaxes
12
+ end
13
+
14
+ # Loads @syntaxes with all the syntax names.
15
+ # Load the syntax files into Textpow instences.
16
+ # ALSO loads the declared_file_types
17
+ # @force_reload: boolean. Forces the syntax to be reloaded, overriding any loaded syntax
18
+ def Uv.load_all_syntaxes(force_reload=false)
19
+ puts "Uv: Loading all syntaxes..." if @debug
20
+ syntax_names.each do |syntax_name|
21
+ load_syntax(syntax_name, force_reload)
22
+ load_syntax_declared_file_types(@syntaxes[syntax_name])
23
+ end
24
+ @syntaxes
25
+ end
26
+
27
+ # Loads @syntaxes[syntax_name] with a Textpow instance
28
+ # @force_reload: boolean. Forces the syntax to be reloaded, overriding any loaded syntax
29
+ def Uv.load_syntax(syntax_name, force_reload=false)
30
+ filename = File.join(@syntax_path, "#{syntax_name}.syntax")
31
+ begin
32
+ if force_reload
33
+ @syntaxes[syntax_name] = Textpow::SyntaxNode.load(filename)
34
+ else
35
+ @syntaxes[syntax_name] ||= Textpow::SyntaxNode.load(filename)
36
+ end
37
+ puts "#{syntax_name}.syntax loaded" if @debug
38
+ rescue => e
39
+ puts "Error in loading syntax: #{syntax_name}. Returning: #{@syntaxes[syntax_name].class}. Error: #{e.message}" if @debug
40
+ end
41
+ return @syntaxes[syntax_name]
42
+ end
43
+
44
+ def Uv.load_syntax_declared_file_types(syntax_node)
45
+ syntax_node.fileTypes.each do |file_type|
46
+ puts "Syntax: #{syntax_node.name} loading FileType: #{file_type}" if @debug
47
+ @syntaxes[file_type] ||= syntax_node
48
+ end if syntax_node and syntax_node.fileTypes
49
+ end
50
+
51
+ end
data/lib/uv/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Uv
2
- VERSION = '0.0.7.2'
2
+ VERSION = '0.0.7.3'
3
3
  end
data/lib/uv.rb CHANGED
@@ -3,14 +3,15 @@ require 'fileutils'
3
3
  require 'textpow'
4
4
  require 'uv/render_processor'
5
5
  require "uv/version"
6
- require "uv/finding_syntaxes"
6
+ require "uv/finding_syntax_nodes"
7
+ require "uv/syntaxes"
7
8
  require 'uv/utility'
8
9
  require 'uv/engine' if defined?(Rails)
9
10
 
10
11
 
11
12
  module Uv
12
13
  class << self
13
- attr_accessor :render_path, :theme_path, :syntax_path, :default_style, :syntaxes
14
+ attr_accessor :render_path, :theme_path, :syntax_path, :default_style, :syntaxes, :debug
14
15
  end
15
16
 
16
17
  self.syntax_path = File.join(File.dirname(__FILE__), '..', 'syntax')
@@ -27,6 +28,17 @@ module Uv
27
28
  end
28
29
 
29
30
 
31
+ # Returns the list of file names in the syntax dir (without '.syntax' extension)
32
+ def Uv.syntax_names
33
+ Dir.glob( File.join(@syntax_path, '*.syntax') ).collect do |f|
34
+ File.basename(f, '.syntax')
35
+ end
36
+ end
37
+
38
+ def Uv.debug=(value)
39
+ @debug=value
40
+ end
41
+
30
42
  # Copies files from the [ruby-uv/render/<arg1>/files/] to the <arg2> output directory
31
43
  def Uv.copy_files output, output_dir
32
44
  Uv.path.each do |dir|
@@ -35,12 +47,6 @@ module Uv
35
47
  end
36
48
  end
37
49
 
38
- # Returns the list of file names[.syntax] in the syntax dir
39
- def Uv.syntaxes
40
- Dir.glob( File.join(@syntax_path, '*.syntax') ).collect do |f|
41
- File.basename(f, '.syntax')
42
- end
43
- end
44
50
 
45
51
  # Returns the list of .css files in the theme directory
46
52
  def Uv.themes
@@ -52,15 +58,16 @@ module Uv
52
58
  # Parses <arg1> text using RenderProcessor.load(Textpow::SyntaxNode.parse(text)), returns the vailid <output>
53
59
  def Uv.parse text, output = "xhtml", syntax_name = nil, line_numbers = false, render_style = nil, headers = false
54
60
  syntaxes = find_syntaxes([syntax_name], get_first_line(text))
55
- syntax_node = syntaxes.first
61
+ return text if syntaxes.empty?
56
62
  RenderProcessor.load(output, render_style, line_numbers, headers) do |processor|
57
- syntax_node.parse(text, processor)
63
+ syntaxes.first.parse(text, processor)
58
64
  end.string
59
65
  end
60
66
 
61
67
  def Uv.get_first_line(text)
62
- first_break = text.index(/[\n\r]/) || text.length - 1
63
- text[0..first_break].strip
68
+ stripped_text = text.strip
69
+ first_break = stripped_text.index(/[\n\r]/) || stripped_text.length - 1
70
+ stripped_text[0..first_break].strip
64
71
  end
65
72
 
66
73
  # Parses <arg1> text with Textpow::DebugProcessor, using the given syntax
data/syntax/build.syntax CHANGED
@@ -1,51 +1,51 @@
1
- ---
1
+ ---
2
2
  name: NAnt Build File
3
- fileTypes:
3
+ fileTypes:
4
4
  - build
5
5
  scopeName: source.nant-build
6
6
  uuid: 1BA72668-707C-11D9-A928-000D93589AF6
7
7
  foldingStartMarker: <[^!?/>]+|<!--
8
- patterns:
8
+ patterns:
9
9
  - name: comment.block.nant
10
- captures:
11
- "0":
10
+ captures:
11
+ "0":
12
12
  name: punctuation.definition.comment.nant
13
13
  begin: <!--
14
14
  end: -->
15
15
  - name: meta.tag.nant
16
- captures:
17
- "1":
16
+ captures:
17
+ "1":
18
18
  name: punctuation.definition.tag.nant
19
- "2":
19
+ "2":
20
20
  name: entity.name.tag.nant
21
21
  begin: (</?)([-_a-zA-Z0-9:]+)
22
22
  end: (/?>)
23
- patterns:
23
+ patterns:
24
24
  - name: entity.other.attribute-name.nant
25
25
  match: " ([a-zA-Z-]+)"
26
26
  - name: string.quoted.double.nant
27
- endCaptures:
28
- "0":
27
+ endCaptures:
28
+ "0":
29
29
  name: punctuation.definition.string.end.nant
30
30
  begin: "\""
31
- beginCaptures:
32
- "0":
31
+ beginCaptures:
32
+ "0":
33
33
  name: punctuation.definition.string.begin.nant
34
34
  end: "\""
35
35
  - name: string.quoted.single.nant
36
- endCaptures:
37
- "0":
36
+ endCaptures:
37
+ "0":
38
38
  name: punctuation.definition.string.end.nant
39
39
  begin: "'"
40
- beginCaptures:
41
- "0":
40
+ beginCaptures:
41
+ "0":
42
42
  name: punctuation.definition.string.begin.nant
43
43
  end: "'"
44
44
  - name: constant.character.entity.nant
45
- captures:
46
- "1":
45
+ captures:
46
+ "1":
47
47
  name: punctuation.definition.constant.nant
48
- "3":
48
+ "3":
49
49
  name: punctuation.definition.constant.nant
50
50
  match: (&)([a-zA-Z]+|#[0-9]+|#x[0-9a-fA-F]+)(;)
51
51
  - name: invalid.illegal.bad-ampersand.nant