ruco 0.2.0.beta11 → 0.2.0.beta12

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0.beta11
1
+ 0.2.0.beta12
@@ -95,4 +95,11 @@ class Object
95
95
  }
96
96
  end
97
97
  end
98
+
99
+ # Memoize class methods
100
+ def cmemoize(*method_names)
101
+ (class << self; self; end).class_eval do
102
+ memoize(*method_names)
103
+ end
104
+ end
98
105
  end
@@ -41,9 +41,8 @@ module Ruco
41
41
  language = @options[:language]
42
42
  possible_languages = [language.name.downcase, language.lexer]
43
43
 
44
- @syntax_info ||= {}
45
44
  lines.map do |line|
46
- @syntax_info[line] ||= SyntaxParser.syntax_for_lines([line], possible_languages).first
45
+ SyntaxParser.syntax_for_line(line, possible_languages)
47
46
  end
48
47
  end
49
48
 
@@ -92,48 +92,45 @@ module Ruco
92
92
  end
93
93
 
94
94
  def self.curses_style(style)
95
- @@styles[style] ||= begin
96
- if $ruco_colors
97
- foreground = $ruco_foreground || '#ffffff'
98
- background = $ruco_background || '#000000'
99
-
100
- foreground, background = if style == :normal
101
- [foreground, background]
102
- elsif style == :reverse
103
- ['#000000', '#ffffff']
104
- else
105
- # :red or [:red, :blue]
106
- f,b = style
107
- [f || foreground, b || background]
108
- end
95
+ if $ruco_colors
96
+ foreground = $ruco_foreground || '#ffffff'
97
+ background = $ruco_background || '#000000'
98
+
99
+ foreground, background = if style == :normal
100
+ [foreground, background]
101
+ elsif style == :reverse
102
+ ['#000000', '#ffffff']
103
+ else
104
+ # :red or [:red, :blue]
105
+ f,b = style
106
+ [f || foreground, b || background]
107
+ end
109
108
 
110
- foreground = html_to_terminal_color(foreground)
111
- background = html_to_terminal_color(background)
112
- color_id(foreground, background)
113
- else # no colors
114
- if style == :reverse
115
- Curses::A_REVERSE
116
- else
117
- Curses::A_NORMAL
118
- end
109
+ foreground = html_to_terminal_color(foreground)
110
+ background = html_to_terminal_color(background)
111
+ color_id(foreground, background)
112
+ else # no colors
113
+ if style == :reverse
114
+ Curses::A_REVERSE
115
+ else
116
+ Curses::A_NORMAL
119
117
  end
120
118
  end
121
119
  end
120
+ cmemoize :curses_style
122
121
 
123
122
  # create a new color from foreground+background or reuse old
124
123
  # and return color-id
125
124
  def self.color_id(foreground, background)
126
- @@color_ids ||= {}
127
- @@color_ids[[foreground, background]] ||= begin
128
- # make a new pair with a unique id
129
- @@max_color_id ||= 0
130
- id = (@@max_color_id += 1)
131
- unless defined? RSpec # stops normal text-output, do not use in tests
132
- Curses::init_pair(id, foreground, background)
133
- end
134
- Curses.color_pair(id)
125
+ # make a new pair with a unique id
126
+ @@max_color_id ||= 0
127
+ id = (@@max_color_id += 1)
128
+ unless defined? RSpec # stops normal text-output, do not use in tests
129
+ Curses::init_pair(id, foreground, background)
135
130
  end
131
+ Curses.color_pair(id)
136
132
  end
133
+ cmemoize :color_id
137
134
 
138
135
  COLOR_SOURCE_VALUES = 256
139
136
  COLOR_TARGET_VALUES = 5
@@ -6,6 +6,11 @@ module Ruco
6
6
  'html+erb' => 'html_rails',
7
7
  }
8
8
 
9
+ def self.syntax_for_line(line, languages)
10
+ syntax_for_lines([line], languages).first
11
+ end
12
+ cmemoize :syntax_for_line
13
+
9
14
  def self.syntax_for_lines(lines, languages)
10
15
  if syntax = syntax_node(languages)
11
16
  processor = syntax.parse(lines.join("\n"), Ruco::ArrayProcessor.new)
@@ -16,18 +21,16 @@ module Ruco
16
21
  end
17
22
 
18
23
  def self.syntax_node(languages)
19
- @@syntax_node ||= {}
20
- @@syntax_node[languages] ||= begin
21
- found = nil
22
- fallbacks = languages.map{|l| TEXTPOW_CONVERT[l] }.compact
24
+ found = nil
25
+ fallbacks = languages.map{|l| TEXTPOW_CONVERT[l] }.compact
23
26
 
24
- (languages + fallbacks).detect do |language|
25
- syntax = File.join(Textpow.syntax_path, "#{language}.syntax")
26
- found = Textpow::SyntaxNode.load(syntax) if File.exist?(syntax)
27
- end
28
-
29
- found
27
+ (languages + fallbacks).detect do |language|
28
+ syntax = File.join(Textpow.syntax_path, "#{language}.syntax")
29
+ found = Textpow::SyntaxNode.load(syntax) if File.exist?(syntax)
30
30
  end
31
+
32
+ found
31
33
  end
34
+ cmemoize :syntax_node
32
35
  end
33
36
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ruco}
8
- s.version = "0.2.0.beta11"
8
+ s.version = "0.2.0.beta12"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Michael Grosser"]
12
- s.date = %q{2011-10-03}
12
+ s.date = %q{2011-10-04}
13
13
  s.default_executable = %q{ruco}
14
14
  s.email = %q{michael@grosser.it}
15
15
  s.executables = ["ruco"]
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruco
3
3
  version: !ruby/object:Gem::Version
4
- hash: 62196373
4
+ hash: 62196379
5
5
  prerelease: 6
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
9
  - 0
10
10
  - beta
11
- - 11
12
- version: 0.2.0.beta11
11
+ - 12
12
+ version: 0.2.0.beta12
13
13
  platform: ruby
14
14
  authors:
15
15
  - Michael Grosser
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2011-10-03 00:00:00 +02:00
20
+ date: 2011-10-04 00:00:00 +02:00
21
21
  default_executable: ruco
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency