Class: Blueprint::Namespace

Inherits:
Object
  • Object
show all
Defined in:
lib/template/css/blueprint/lib/blueprint/namespace.rb

Instance Method Summary collapse

Constructor Details

#initialize(path, namespace) ⇒ Namespace

Read html to string, remove namespace if any, set the new namespace, and update the test file.



6
7
8
9
10
11
# File 'lib/template/css/blueprint/lib/blueprint/namespace.rb', line 6

def initialize(path, namespace)
  html = File.path_to_string(path)
  remove_current_namespace(html)
  add_namespace(html, namespace)
  File.string_to_file(html, path)
end

Instance Method Details

#add_namespace(html, namespace) ⇒ Object

adds namespace to BP classes in a html file



14
15
16
17
18
19
20
21
# File 'lib/template/css/blueprint/lib/blueprint/namespace.rb', line 14

def add_namespace(html, namespace)
  html.gsub!(/(class=")([a-zA-Z0-9\-_ ]*)(")/) do |m|
    classes = m.to_s.split('"')[1].split(" ")
    classes.map! { |c| c = namespace + c }
    'class="' + classes.join(' ') + '"'
  end
  html
end

#current_namespace(html) ⇒ Object

returns current namespace in test files based on container class



32
33
34
35
36
# File 'lib/template/css/blueprint/lib/blueprint/namespace.rb', line 32

def current_namespace(html)
  html =~ /class="([\S]+)container/
  current_namespace = $1 if $1
  current_namespace || ""
end

#remove_current_namespace(html) ⇒ Object

removes a namespace from a string of html



24
25
26
27
28
# File 'lib/template/css/blueprint/lib/blueprint/namespace.rb', line 24

def remove_current_namespace(html)
  current = current_namespace(html)
  html.gsub!(current, "")
  html
end