Module: Uv

### Home Classes Methods

### In Files

- lib/uv.rb
- lib/uv/render_processor.rb
- lib/uv/utility.rb
- lib/uv/version.rb

### Namespace

- CLASS Uv::RenderProcessor

### Methods

- ::alpha_blend
- ::copy_files
- ::debug
- ::foreground
- ::normalize_color
- ::parse
- ::path
- ::syntax_for_file
- ::syntax_node_for
- ::syntaxes
- ::themes

### Class/Module Index

Quicksearch

- Uv
- Uv::RenderProcessor

No matching classes.

# Uv

### Constants

Version

### Attributes

default_style[RW]
render_path[RW]
syntax_path[RW]
theme_path[RW]

### Public Class Methods

alpha_blend(bg, fg) click to toggle source

    # File lib/uv/utility.rb, line 10
    def Uv.alpha_blend bg, fg
      unless bg =~ /^#((\d|[ABCDEF]){3}|(\d|[ABCDEF]){6}|(\d|[ABCDEF]){8})$/
        raise(ArgumentError, "Malformed background color '#{bg}'" )
      end
      unless fg =~ /^#((\d|[ABCDEF]){3}|(\d|[ABCDEF]){6}|(\d|[ABCDEF]){8})$/
        raise(ArgumentError, "Malformed foreground color '#{fg}'" )
      end

      if bg.size == 4
        tbg  =  (fg[1,1].hex * 0xff / 0xf).to_s(16).upcase.rjust(2, '0')
        tbg +=  (fg[2,1].hex * 0xff / 0xf).to_s(16).upcase.rjust(2, '0')
        tbg +=  (fg[3,1].hex * 0xff / 0xf).to_s(16).upcase.rjust(2, '0')
        bg   =  "##{tbg}"
      end

      result = ""
      if fg.size == 4
        result += (fg[1,1].hex * 0xff / 0xf).to_s(16).upcase.rjust(2, '0')
        result += (fg[2,1].hex * 0xff / 0xf).to_s(16).upcase.rjust(2, '0')
        result += (fg[3,1].hex * 0xff / 0xf).to_s(16).upcase.rjust(2, '0')
      elsif fg.size == 9
        if bg.size == 7
          div0 = bg[1..-1].hex
          div1, alpha = fg[1..-1].hex.divmod( 0x100 )
          3.times {
            div0, mod0 = div0.divmod( 0x100 )
            div1, mod1 = div1.divmod( 0x100 )
            result = ((mod0 * alpha + mod1 * ( 0x100 - alpha ) ) / 0x100).to_s(16).upcase.rjust(2, '0') + result
          }
        else
          div_a, alpha_a = bg[1..-1].hex.divmod( 0x100 )
          div_b, alpha_b = fg[1..-1].hex.divmod( 0x100 )
          alpha = alpha_a + alpha_b * (0x100 - alpha_a)
          3.times {
            div_b, c_b = div_b.divmod( 0x100 )
            div_a, c_a = div_a.divmod( 0x100 )
            result = ((c_a * alpha_a + ( 0x100 - alpha_a ) * alpha_b * c_b ) / alpha).to_s(16).upcase.rjust(2, '0') + result
          }
        end
        #result = "FF00FF"
      else
        result = fg[1..-1]
      end
      "##{result}"
    end

copy_files(output, output_dir) click to toggle source

    # File lib/uv.rb, line 30
    def self.copy_files(output, output_dir)
      Uv.path.each do |dir|
        dir_name = File.join( dir, "render", output, "files" )
        FileUtils.cp_r( Dir.glob(File.join( dir_name, "." )), output_dir ) if File.exists?( dir_name )
      end
    end

debug(text, syntax_name) click to toggle source

    # File lib/uv.rb, line 89
    def self.debug(text, syntax_name)
      syntax_node_for(syntax_name).parse(text, Textpow::DebugProcessor.new)
    end

foreground(bg) click to toggle source

    # File lib/uv/utility.rb, line 2
    def Uv.foreground bg
      fg = "#FFFFFF"
      3.times do |i|
        fg = "#000000" if bg[i*2+1, 2].hex > 0xFF / 2
      end
      fg
    end

normalize_color(settings, color, fg = false) click to toggle source

    # File lib/uv/utility.rb, line 56
    def Uv.normalize_color settings, color, fg = false
      if color
        if fg
          alpha_blend( settings["foreground"] ? settings["foreground"] : "#000000FF", color )
        else
          alpha_blend( settings["background"] ? settings["background"] : "#000000FF", color )
        end
      else
        color
      end
    end

parse(text, output = "xhtml", syntax_name = nil, line_numbers = false, render_style = nil, headers = false) click to toggle source

    # File lib/uv.rb, line 83
    def self.parse(text, output = "xhtml", syntax_name = nil, line_numbers = false, render_style = nil, headers = false)
      RenderProcessor.load(output, render_style, line_numbers, headers) do |processor|
        syntax_node_for(syntax_name).parse(text, processor)
      end.string
    end

path() click to toggle source

    # File lib/uv.rb, line 17
    def self.path
      result = []
      result << File.join(File.dirname(__FILE__), ".." )
    end

syntax_for_file(file_name) click to toggle source

    # File lib/uv.rb, line 54
    def self.syntax_for_file(file_name)
      # get first non-empty line
      first_line = ""
      File.open( file_name, 'r' ) { |f|
        while (first_line = f.readline).strip.size == 0; end
      }

      # find syntax by file-extension
      result = []
      syntax_nodes.each do |key, syntax|
        assigned = false
        if syntax.fileTypes
          syntax.fileTypes.each do |t|
            if t == File.basename( file_name ) || t == File.extname( file_name )[1..-1]
              result << [key, syntax]
              assigned = true
              break
            end
          end
        end
        unless assigned
          if syntax.firstLineMatch && syntax.firstLineMatch =~ first_line
            result << [key, syntax]
          end
        end
      end
      result
    end

syntax_node_for(syntax) click to toggle source

    # File lib/uv.rb, line 22
    def self.syntax_node_for(syntax)
      if syntax_nodes.key?(syntax)
        syntax_nodes[syntax]
      else
        syntax_nodes[syntax] = Textpow.syntax(syntax) || raise(ArgumentError, "No syntax found for #{syntax}")
      end
    end

syntaxes() click to toggle source

    # File lib/uv.rb, line 37
    def self.syntaxes
      Dir.glob( File.join(@syntax_path, '*.syntax') ).collect do |f|
        File.basename(f, '.syntax')
      end
    end

themes() click to toggle source

    # File lib/uv.rb, line 48
    def self.themes
      Dir.glob( File.join(@theme_path, '*.css') ).collect do |f|
        File.basename(f, '.css')
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.