Class: Uv::Converters

Inherits:
Object
  • Object
show all
Defined in:
lib/rmthemegen/uv_addons.rb

Constant Summary collapse

@@render_path =
""
@@css_path =
""

Class Method Summary collapse

Class Method Details

.settingsObject

the following generates a “.render” file that can be used by ultraviolet to later create css and xhtml files to display a theme in the browser



9
10
11
12
13
14
# File 'lib/rmthemegen/uv_addons.rb', line 9

def self.settings
   unless @settings
      @settings = @theme["settings"].find { |s| ! s["name"] }["settings"]
   end
   @settings
end

.tmtheme2render(theme_file, output_file_path) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/rmthemegen/uv_addons.rb', line 16

def self.tmtheme2render(theme_file, output_file_path)

    require 'uv/utility'

    #base_dir = File.join( File.dirname(__FILE__), '..', 'render' )
    base_dir = output_file_path


    puts "Processing #{theme_file}"

    @theme = Plist::parse_xml( theme_file )

    render = {"name" => @theme["name"]}
    css = {}

    standard_name = File.basename( theme_file ).downcase.gsub(/\s+/, '_').gsub('.tmtheme', '').gsub(/\W/, '').gsub(/_+/, '_')
    code_name = "pre.#{standard_name}"

    render["tags"] = []
    count_names = {}
#    puts @theme.each do |i| i.inspect end ;
 #   puts @theme.inspect 
#    puts @theme.methods
#    puts @theme.class

 #   puts 'standard_name = '+standard_name 
 #   puts 'code_name = '+code_name 
 #   puts @theme.keys
    @theme["settings"].each do |t|
       if t["scope"]
          class_name = t["name"].downcase.gsub(/\W/, ' ').gsub('.tmtheme', '').split(' ').collect{|s| s.capitalize}.join
          if class_name == ""
             class_name = "x" * t["name"].size
          end
          
          if count_names[class_name]
             tname = class_name
             class_name = "#{class_name}#{count_names[class_name]}"
             count_names[tname] += count_names[tname] + 1
          else
             count_names[class_name] = 1
          end
          
          tag = {}
          tag["selector"] = t["scope"]
          tag["begin"] = "<span class=\"#{class_name}\">"
          tag["end"] = "</span>"
          render["tags"] << tag
          
          if s = t["settings"]
             style = {}
             style["color"] = Uv.normalize_color(settings, s["foreground"], true)
             style["background-color"] = Uv.normalize_color(settings, s["background"])
             case s["fontStyle"]
                when /bold/ then style["font-weight"] = "bold"
                when /italic/ then style["font-style"] = "italic"
                when /underline/ then style["text-decoration"] = "underline"
             end
             css[".#{class_name}"] = style
          end
       elsif ! t["name"]
          if s = t["settings"]
             style = {}
             style["color"] = Uv.normalize_color(settings, s["foreground"], true)
             style["background-color"] = Uv.alpha_blend(s["background"], s["background"])
             css[code_name] = style
             @style = style
             style = {}
             style["background-color"] = Uv.alpha_blend(s["selection"], s["selection"])
             style["color"] = Uv.foreground( style["background-color"] )
             css[".line-numbers"] = style
             
             tag = {}
             tag["begin"] = "<span class=\"line-numbers\">"
             tag["end"] = "</span>"
             render["line-numbers"] = tag
          end
       end
    end

    render["filter"] = "CGI.escapeHTML( @escaped )"

    tag = {}
    tag["begin"] = ""
    tag["end"]   = ""
    render["line"] = tag


    tag = {}
    tag["begin"] = "<pre class=\"#{standard_name}\">"
    tag["end"]   = "</pre>"
    render["listing"] = tag

    tag = {}
    tag["begin"] = <<END
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en">

    <head>
      <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
      <meta http-equiv="cache-control" content="no-cache" />
      <meta http-equiv="expires" content="3600" />
      <meta name="revisit-after" content="2 days" />
      <meta name="robots" content="index,follow" />
      <meta name="publisher" content="Dichodaemon" />
      <meta name="copyright" content="Dichodaemon" />

      <meta name="author" content="Dichodaemon" />
      <meta name="distribution" content="global" />
      <meta name="description" content="Ocatarinetabellachithchix" />
      <meta name="keywords" content="arzaversperia flexilimosos toves" />
      <link rel="stylesheet" type="text/css" media="screen,projection,print" href="css/#{standard_name}.css" />
      <title>#{standard_name}</title>

    </head>

    <body>
END

    tag["end"] = <<END
      <p>
        <a href="http://validator.w3.org/check?uri=referer">
          <img style="border:0"
               src="http://www.w3.org/Icons/valid-xhtml10"
               alt="Valid XHTML 1.0 Strict" height="31" width="88" />
        </a>
        <a href="http://jigsaw.w3.org/css-validator/check?uri=referer">
          <img style="border:0;width:88px;height:31px"
               src="http://jigsaw.w3.org/css-validator/images/vcss" 
               alt="Valid CSS!" />
        </a>
      </p>
    </body>
    </html>
END

    render["document"] = tag

#        File.open( File.join( base_dir, "xhtml", "#{standard_name}.render" ), "w" ) {|f| YAML.dump( render, f ) }
    File.open( File.join( base_dir, "#{standard_name}.render" ), "w" ) {|f| YAML.dump( render, f ) }

#        File.open( File.join( base_dir, "xhtml", "files", "css", "#{standard_name}.css" ), "w" ) do |f|
    File.open( File.join( base_dir, "#{standard_name}.css" ), "w" ) do |f|
       css.each do |key, values|
          if key == code_name
             f.puts "#{code_name} {"
             #puts @style
          else
             f.puts "#{code_name} #{key} {"
          end
          values.each do |style, value|
             f.puts "   #{style}: #{value};" if value
          end
          f.puts "}"
       end
    end

end