Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit bca6d6f
Showing
9 changed files
with
175 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
syntax: glob | ||
.project | ||
.pydevproject | ||
*.pyc | ||
.tox | ||
Flask_Scss.egg-info |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright (C) 2011 by Bruno Carlin <self@aerdhyl.eu> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.. -*- restructuredtext -*- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__import__('pkg_resources').declare_namespace(__name__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import os.path as op | ||
import os | ||
import scss | ||
|
||
|
||
class Scss(object): | ||
def __init__(self, app): | ||
self.app = app | ||
self.asset_dir = self.set_asset_dir() | ||
self.static_dir = self.set_static_dir() | ||
self.assets = {} | ||
self.compiler = scss.Scss().compile | ||
self.set_hooks() | ||
|
||
def set_asset_dir(self): | ||
asset_dir = op.join(self.app.root_path, 'assets', 'scss') | ||
if op.exists(asset_dir): | ||
return asset_dir | ||
return None | ||
|
||
def set_static_dir(self): | ||
static_dir = op.join(self.app.root_path, self.app.static_folder) | ||
if op.exists(op.join(static_dir, 'css')): | ||
return op.join(static_dir, 'css') | ||
if op.exists(static_dir): | ||
return static_dir | ||
return None | ||
|
||
def set_hooks(self): | ||
if self.asset_dir is None: | ||
self.app.logger.warning("The asset directory cannot be found." | ||
"PyScss extension has been disabled") | ||
return | ||
self.app.logger.info("Pyscss loaded!") | ||
self.app.before_request(self.update_scss) | ||
|
||
def discover_scss(self): | ||
for filename in (f for f in os.listdir(self.asset_dir) if f.endswith('.scss')): | ||
if filename not in self.assets: | ||
src_path = op.join(self.asset_dir, filename) | ||
dest_path = op.join(self.static_dir, | ||
filename.replace('.scss', '.css')) | ||
self.assets[filename] = { | ||
'src_path': src_path, | ||
'dest_path': dest_path | ||
} | ||
|
||
|
||
def update_scss(self): | ||
self.discover_scss() | ||
for asset in self.assets.values(): | ||
dest_mtime = op.getmtime(asset['dest_path']) \ | ||
if op.exists(asset['dest_path']) \ | ||
else -1 | ||
if op.getmtime(asset['src_path']) > dest_mtime: | ||
self.compile_scss(asset) | ||
|
||
def compile_scss(self, asset): | ||
self.app.logger.info("[flask-pyscss] refreshing {}".format(asset['dest_path'])) | ||
with open(asset['dest_path'], 'w') as fo, \ | ||
open(asset['src_path']) as fi: | ||
fo.write(self.compiler(fi.read())) | ||
|
||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
''' | ||
Created on 7 juil. 2011 | ||
@author: bubu | ||
''' | ||
import unittest | ||
|
||
|
||
class ScssTest(unittest.TestCase): | ||
|
||
|
||
def setUp(self): | ||
pass | ||
|
||
|
||
def tearDown(self): | ||
pass | ||
|
||
|
||
def testName(self): | ||
pass | ||
|
||
|
||
if __name__ == "__main__": | ||
#import sys;sys.argv = ['', 'Test.testName'] | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
""" | ||
Flask-scss | ||
------------- | ||
This extension brings support for scss files to Flask | ||
""" | ||
from setuptools import setup | ||
|
||
|
||
setup( | ||
name='Flask-Scss', | ||
version='0.1', | ||
url='https://bitbucket.org/aerdhyl/flask-scss', | ||
license='MIT', | ||
author='Bruno Carlin', | ||
author_email='self@aerdhyl.eu', | ||
description='This extension brings support for scss files to Flask', | ||
long_description=open('README.txt').read(), | ||
packages=['flaskext'], | ||
namespace_packages=['flaskext'], | ||
zip_safe=False, | ||
platforms='any', | ||
install_requires=[ | ||
'Flask', 'pyScss' | ||
], | ||
classifiers=[ | ||
'Development Status :: 4 - Beta' | ||
'Environment :: Web Environment', | ||
'Intended Audience :: Developers', | ||
'License :: OSI Approved :: MIT License', | ||
'Operating System :: OS Independent', | ||
'Programming Language :: Python', | ||
'Topic :: Internet :: WWW/HTTP :: Dynamic Content', | ||
'Topic :: Software Development :: Libraries :: Python Modules' | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
[tox] | ||
envlist = py25,py26,py27 | ||
|
||
[testenv] | ||
deps= | ||
nose | ||
commands=nosetests # or 'nosetests' or ... | ||
|
||
[testenv:py27] | ||
basepython=/usr/bin/python2.7 | ||
|
||
[testenv:py26] | ||
deps= | ||
unittest2 | ||
nose | ||
basepython=/usr/local/python26/bin/python2.6 | ||
|
||
[testenv:py25] | ||
deps= | ||
unittest2 | ||
nose | ||
basepython=/usr/local/python25/bin/python2.5 |