source: ether_2012/web/resources/css/blueprint-css/lib/blueprint/namespace.rb @ 319

Last change on this file since 319 was 319, checked in by vmipsl, 12 years ago

Import du projet Ether pour le nouveau look 2012

File size: 1.0 KB
Line 
1module Blueprint
2  class Namespace
3
4    # Read html to string, remove namespace if any,
5    # set the new namespace, and update the test file.
6    def initialize(path, namespace)
7      html = File.path_to_string(path)
8      remove_current_namespace(html)
9      add_namespace(html, namespace)
10      File.string_to_file(html, path)
11    end
12
13    # adds namespace to BP classes in a html file
14    def add_namespace(html, namespace)
15      html.gsub!(/(class=")([a-zA-Z0-9\-_ ]*)(")/) do |m|
16        classes = m.to_s.split('"')[1].split(" ")
17        classes.map! { |c| c = namespace + c }
18        'class="' + classes.join(' ') + '"'
19      end
20      html
21    end
22
23    # removes a namespace from a string of html
24    def remove_current_namespace(html)
25      current = current_namespace(html)
26      html.gsub!(current, "")
27      html
28    end
29
30    # returns current namespace in test files
31    # based on container class
32    def current_namespace(html)
33      html =~ /class="([\S]+)container/
34      current_namespace = $1 if $1
35      current_namespace || ""
36    end
37  end
38end
Note: See TracBrowser for help on using the repository browser.