def test_compiling(self, sample_coffee): compiled_js = '\ (function(){var foo;foo=function(str){alert(str);return true;};\ foo("Hello CoffeeScript!");}).call(this);' xc = jac.compile(sample_coffee, 'text/coffeescript') print (xc) assert jac.compile(sample_coffee, 'text/coffeescript') == compiled_js
def test_compiling(self, sample_sass): compiled_css = """.content-navigation { border-color: #3bbfce; color: #2ca2af; } .border { padding: 8px; margin: 8px; border-color: #3bbfce; } """ assert jac.compile(sample_sass, 'text/sass') == compiled_css
def _compile(self, compression_type, caller): compression_type = compression_type.lower() html = caller() soup = BeautifulSoup(html) compilables = self._find_compilable_tags(soup) text = "" html_hash = self._make_hash(html, self._find_compilable_tags(soup)) cached_file = os.path.join(str(self.environment.compressor_output_dir), "%s.%s") % (html_hash, compression_type) if os.path.exists(cached_file): return self._render_block(cached_file, compression_type) for c in compilables: if c.get("type") is None: raise RuntimeError("Tags to be compressed must have a compression_type.") src = c.get("src") or c.get("href") if src: src = open(self._find_file(str(src)), "rb") cwd = [os.path.dirname(src.name)] else: src = c.string cwd = [] cwd += self.environment.compressor_sass_paths if c.name == "link" and c.get("rel", [""])[0].lower() != "stylesheet": text += self._get_contents(src) if c["type"].lower() in ("text/css", "text/javascript"): text += self._get_contents(src) else: text += compile(self._get_contents(src), c["type"], cwd=cwd) with open(cached_file, "w") as f: f.write(text) return self._render_block(cached_file, compression_type)
def _compile(self, compression_type, caller): compression_type = compression_type.lower() html = caller() soup = BeautifulSoup(html) compilables = self._find_compilable_tags(soup) text = '' html_hash = self._make_hash(html, self._find_compilable_tags(soup)) cached_file = os.path.join(str(self.environment.compressor_output_dir), '%s.%s') % (html_hash, compression_type) if os.path.exists(cached_file): return self._render_block(cached_file, compression_type) for c in compilables: if c.get('type') is None: raise RuntimeError('Tags to be compressed must have a compression_type.') src = c.get('src') or c.get('href') if src: src = open(self._find_file(str(src)), 'rb') cwd = os.path.dirname(src.name) else: src = c.string cwd = None if c.name == 'link' and c.get('rel', [''])[0].lower() != 'stylesheet': text += self._get_contents(src) if c['type'].lower() in ('text/css', 'text/javascript'): text += self._get_contents(src) else: text += compile(self._get_contents(src), c['type'], cwd=cwd) with open(cached_file, 'w') as f: f.write(text) return self._render_block(cached_file, compression_type)
def test_compiling(self, sample_less): compiled_css = 'body .test-class{color:#fff}' assert jac.compile(sample_less, 'text/less') == compiled_css
def test_compiling(self, sample_coffee): compiled_js = '\ (function(){var foo;foo=function(str){alert(str);return true;};\ foo("Hello CoffeeScript!");}).call(this);' assert jac.compile(sample_coffee, 'text/coffeescript') == compiled_js