photomix/resources/DummyHTML/css/joshuaclayton-blueprint-css-05312a805eca539ab85e435cfd94bdedfd12ab2e/doc/classes/Blueprint/SemanticClassNames.src/M000010.html

50 lines
6 KiB
HTML
Raw Normal View History

2009-06-09 21:38:32 +02:00
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>css_from_assignments (Blueprint::SemanticClassNames)</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
</head>
<body class="standalone-code">
<pre><span class="ruby-comment cmt"># File lib/blueprint/semantic_class_names.rb, line 21</span>
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">css_from_assignments</span>(<span class="ruby-identifier">assignments</span> = {})
<span class="ruby-identifier">assignments</span> <span class="ruby-operator">||=</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class_assignments</span>
<span class="ruby-comment cmt"># define a wrapper hash to hold all the new CSS assignments</span>
<span class="ruby-identifier">output_css</span> = {}
<span class="ruby-comment cmt">#loads full stylesheet into an array of hashes</span>
<span class="ruby-identifier">blueprint_assignments</span> = <span class="ruby-constant">CSSParser</span>.<span class="ruby-identifier">new</span>(<span class="ruby-constant">File</span>.<span class="ruby-identifier">path_to_string</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">source_file</span>)).<span class="ruby-identifier">parse</span>
<span class="ruby-comment cmt"># iterates through each class assignment ('#footer' =&gt; '.span-24 div.span-24', '#header' =&gt; '.span-24 div.span-24')</span>
<span class="ruby-identifier">assignments</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">semantic_class</span>, <span class="ruby-identifier">blueprint_classes</span><span class="ruby-operator">|</span>
<span class="ruby-comment cmt"># gathers all BP classes we're going to be mimicing</span>
<span class="ruby-identifier">blueprint_classes</span> = <span class="ruby-identifier">blueprint_classes</span>.<span class="ruby-identifier">split</span>(<span class="ruby-regexp re">/,|\s/</span>).<span class="ruby-identifier">find_all</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">c</span><span class="ruby-operator">|</span> <span class="ruby-operator">!</span><span class="ruby-identifier">c</span>.<span class="ruby-identifier">blank?</span> }.<span class="ruby-identifier">flatten</span>.<span class="ruby-identifier">map</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">c</span><span class="ruby-operator">|</span> <span class="ruby-identifier">c</span>.<span class="ruby-identifier">strip</span> }
<span class="ruby-identifier">classes</span> = []
<span class="ruby-comment cmt"># loop through each BP class, grabbing the full hash (containing tags, index, and CSS rules)</span>
<span class="ruby-identifier">blueprint_classes</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">bp_class</span><span class="ruby-operator">|</span>
<span class="ruby-identifier">match</span> = <span class="ruby-identifier">bp_class</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-value str">'.'</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">bp_class</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-value str">&quot;.&quot;</span>, <span class="ruby-node">&quot;.#{self.namespace}&quot;</span>) <span class="ruby-operator">:</span> <span class="ruby-node">&quot;.#{self.namespace}#{bp_class}&quot;</span>
<span class="ruby-identifier">classes</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">blueprint_assignments</span>.<span class="ruby-identifier">find_all</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">line</span><span class="ruby-operator">|</span> <span class="ruby-identifier">line</span>[<span class="ruby-identifier">:tags</span>] <span class="ruby-operator">=~</span> <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>(<span class="ruby-node">/^([\w\.\-]+, ?)*#{match}(, ?[\w\.\-]+)*$/</span>) }.<span class="ruby-identifier">uniq</span>
<span class="ruby-keyword kw">end</span>
<span class="ruby-comment cmt"># clean up the array</span>
<span class="ruby-identifier">classes</span> = <span class="ruby-identifier">classes</span>.<span class="ruby-identifier">flatten</span>.<span class="ruby-identifier">uniq</span>
<span class="ruby-comment cmt"># set the semantic class to the rules gathered in classes, sorted by index</span>
<span class="ruby-comment cmt"># this way, the styles will be applied in the correct order from top of file to bottom</span>
<span class="ruby-identifier">output_css</span>[<span class="ruby-identifier">semantic_class</span>] = <span class="ruby-node">&quot;#{classes.sort_by {|i| i[:idx]}.map {|i| i[:rules]}}&quot;</span>
<span class="ruby-keyword kw">end</span>
<span class="ruby-comment cmt"># return the css in proper format</span>
<span class="ruby-identifier">css</span> = <span class="ruby-value str">&quot;&quot;</span>
<span class="ruby-identifier">output_css</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">tags</span>, <span class="ruby-identifier">rules</span><span class="ruby-operator">|</span>
<span class="ruby-identifier">css</span> <span class="ruby-operator">+=</span> <span class="ruby-node">&quot;#{tags} {#{rules}}\n&quot;</span>
<span class="ruby-keyword kw">end</span>
<span class="ruby-identifier">css</span>
<span class="ruby-keyword kw">end</span></pre>
</body>
</html>