Class: Blueprint::Namespace
- Inherits:
-
Object
- Object
- Blueprint::Namespace
- Defined in:
- lib/blueprint/namespace.rb
Instance Method Summary (collapse)
-
- (Object) add_namespace(html, namespace)
adds namespace to BP classes in a html file.
-
- (Object) current_namespace(html)
returns current namespace in test files based on container class.
-
- (Namespace) initialize(path, namespace)
constructor
Read html to string, remove namespace if any, set the new namespace, and update the test file.
-
- (Object) remove_current_namespace(html)
removes a namespace from a string of html.
Constructor Details
- (Namespace) initialize(path, 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/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
- (Object) add_namespace(html, namespace)
adds namespace to BP classes in a html file
14 15 16 17 18 19 20 21 |
# File '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 |
- (Object) current_namespace(html)
returns current namespace in test files based on container class
32 33 34 35 36 |
# File 'lib/blueprint/namespace.rb', line 32 def current_namespace(html) html =~ /class="([\S]+)container/ current_namespace = $1 if $1 current_namespace || "" end |
- (Object) remove_current_namespace(html)
removes a namespace from a string of html
24 25 26 27 28 |
# File 'lib/blueprint/namespace.rb', line 24 def remove_current_namespace(html) current = current_namespace(html) html.gsub!(current, "") html end |