Sha256: db08fe945a5a155d146c91a1a4342b90648222d2838486dfb7844ae2afc17a60

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

module Blueprint
  class Namespace
  
    # Read html to string, remove namespace if any,
    # set the new namespace, and update the test file.
    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
  
    # adds namespace to BP classes in a html file
    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
  
    # removes a namespace from a string of html
    def remove_current_namespace(html)
      current = current_namespace(html)
      html.gsub!(current, '')
      html
    end
  
    # returns current namespace in test files
    # based on container class
    def current_namespace(html)
      html =~ /class="([\S]+)container/
      current_namespace = $1 if $1
      current_namespace || ''
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
blueprintr-0.1.0 lib/blueprint-css/lib/blueprint/namespace.rb