Skip to content

Commit

Permalink
fanstatic branch initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
tobes committed May 8, 2012
1 parent 9349245 commit de258ae
Show file tree
Hide file tree
Showing 8 changed files with 821 additions and 0 deletions.
24 changes: 24 additions & 0 deletions LICENSE.txt
Expand Up @@ -114,4 +114,28 @@ The above copyright notice and this permission notice shall be included in all c

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.

rjsmin / rcssmin
----------------

Parts of these packages are include in the include directory of ckan.
Full packages can be found at.
http://opensource.perlig.de/rjsmin/
http://opensource.perlig.de/rcssmin/

They both are licensed under Approved License, Version 2

Copyright 2011, 2012
Andr\xe9 Malo or his licensors, as applicable

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

99 changes: 99 additions & 0 deletions ckan/html_resources/__init__.py
@@ -0,0 +1,99 @@
import os.path
import sys
import ConfigParser

from fanstatic import Library, Resource

from ckan.include.rjsmin import jsmin
from ckan.include.rcssmin import cssmin

# TODO
# loop through dirs to setup
# warn on no entry point provided for fanstatic

def setup(name, path):

def min_path(path):
''' return the .min filename eg moo.js -> moo.min.js '''
if f.endswith('.js'):
return path[:-3] + '.min.js'
if f.endswith('.css'):
return path[:-4] + '.min.css'

def minify(filename, min_function):
''' Minify file path using min_function. '''
# if the minified file was modified after the source file we can
# assume that it is up-to-date
path = os.path.join(resource_path, filename)
path_min = min_path(path)
op = os.path
if op.exists(path_min) and op.getmtime(path) < op.getmtime(path_min):
return
source = open(path, 'r').read()
f = open(path_min, 'w')
f.write(min_function(source))
f.close()
print 'minified %s' % path

def create_resource(filename):
''' create the fanstatic Resource '''
# resource_name is name of the file without the .js/.css
resource_name = '.'.join(filename.split('.')[:-1])
kw = {}
path_min = min_path(os.path.join(resource_path, filename))
if os.path.exists(path_min):
kw['minified'] = min_path(filename)
if filename.endswith('.js'):
kw['bottom'] = True
if resource_name in depends:
dependencies = []
for dependency in depends[resource_name]:
dependencies.append(getattr(module, dependency))
kw['depends'] = dependencies
if resource_name in dont_bundle:
kw['dont_bundle'] = True

resource = Resource(library, filename, **kw)
# add the resource to this module
setattr(module, resource_name, resource)

order = []
dont_bundle = []
depends = {}

# parse the config.ini file if it exists
resource_path = os.path.dirname(__file__)
resource_path = os.path.join(resource_path, path)
config_path = os.path.join(resource_path, 'config.ini')
if os.path.exists(config_path):
config = ConfigParser.RawConfigParser()
config.read(config_path)
if config.has_option('main', 'order'):
order = config.get('main', 'order').split()
if config.has_option('main', 'dont_bundle'):
dont_bundle = config.get('main', 'dont_bundle').split()
if config.has_section('depends'):
items = config.items('depends')
depends = dict((n, v.split()) for (n, v) in items)

library = Library(name, path)
module = sys.modules[__name__]

# process each .js/.css file found
for dirname, dirnames, filenames in os.walk(resource_path):
for x in reversed(order):
if x in filenames:
filenames.remove(x)
filenames.insert(0, x)
for f in filenames:
if f.endswith('.js') and not f.endswith('.min.js'):
minify(f, jsmin)
create_resource(f)
if f.endswith('.css') and not f.endswith('.min.css'):
minify(f, cssmin)
create_resource(f)
# finally add the library to this module
setattr(module, name, library)


setup('resources', 'resources')
37 changes: 37 additions & 0 deletions ckan/include/README.txt
@@ -0,0 +1,37 @@
rjsmin.py
is taken from the rjsmin project and licensed under Apache License, Version 2
http://opensource.perlig.de/rjsmin/

# Copyright 2011, 2012
# Andr\xe9 Malo or his licensors, as applicable
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

rcssmin.py
is taken from the rcssmin project and licensed under Apache License, Version 2
http://opensource.perlig.de/rcssmin/

# Copyright 2011, 2012
# Andr\xe9 Malo or his licensors, as applicable
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
Empty file added ckan/include/__init__.py
Empty file.

0 comments on commit de258ae

Please sign in to comment.