Browse Source

Start CP via grunt

pull/5180/head
Ruud 11 years ago
parent
commit
d77cfb3e69
  1. 25
      Gruntfile.js
  2. 36
      couchpotato/core/_base/clientscript.py
  3. 24
      couchpotato/static/scripts/reloader.js
  4. 20
      couchpotato/templates/index.html

25
Gruntfile.js

@ -2,6 +2,8 @@
module.exports = function(grunt){
require('time-grunt')(grunt);
// Configurable paths
var config = {
tmp: '.tmp',
@ -68,32 +70,30 @@ module.exports = function(grunt){
}
},
shell: {
runCouchPotato: {
command: 'python CouchPotato.py'
}
},
// COOL TASKS ==============================================================
watch: {
scss: {
files: ['<%= config.base %>/**/*.{scss,sass}'],
tasks: ['sass:server', 'autoprefixer', 'cssmin'],
options: {
'livereload': true
}
tasks: ['sass:server', 'autoprefixer', 'cssmin']
},
js: {
files: [
'<%= config.base %>/**/*.js'
],
tasks: ['jshint'],
options: {
'livereload': true
}
tasks: ['jshint']
},
livereload: {
options: {
livereload: 35729
},
files: [
'<%= config.base %>/{,*/}*.html',
'<%= config.tmp %>/styles/{,*/}*.css',
'<%= config.base %>/images/{,*/}*'
'<%= config.css_dest %>'
]
}
},
@ -102,7 +102,7 @@ module.exports = function(grunt){
options: {
logConcurrentOutput: true
},
tasks: ['sass:server', 'autoprefixer', 'cssmin', 'watch']
tasks: ['shell:runCouchPotato', 'sass:server', 'autoprefixer', 'cssmin', 'watch']
}
});
@ -114,6 +114,7 @@ module.exports = function(grunt){
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-autoprefixer');
grunt.loadNpmTasks('grunt-concurrent');
grunt.loadNpmTasks('grunt-shell');
grunt.registerTask('default', ['concurrent']);

36
couchpotato/core/_base/clientscript.py

@ -109,7 +109,6 @@ class ClientScript(Plugin):
data_combined = ''
raw = []
new_paths = []
for x in paths:
file_path, url_path = x
@ -117,14 +116,7 @@ class ClientScript(Plugin):
f = open(file_path, 'r').read()
if not Env.get('dev'):
if file_type == 'script':
data = f
else:
data = self.prefix(f)
data = data.replace('../images/', '../static/images/')
data = data.replace('../fonts/', '../static/fonts/')
data = data.replace('../../static/', '../static/') # Replace inside plugins
data = f
data_combined += self.comment.get(file_type) % (ss(file_path), int(os.path.getmtime(file_path)))
data_combined += data + '\n\n'
@ -172,29 +164,3 @@ class ClientScript(Plugin):
if not self.paths[type].get(location):
self.paths[type][location] = []
self.paths[type][location].append((file_path, api_path))
prefix_properties = ['border-radius', 'transform', 'transition', 'box-shadow']
prefix_tags = ['ms', 'moz', 'webkit']
def prefix(self, data):
trimmed_data = re.sub('(\t|\n|\r)+', '', data)
new_data = ''
colon_split = trimmed_data.split(';')
for splt in colon_split:
curl_split = splt.strip().split('{')
for curly in curl_split:
curly = curly.strip()
for prop in self.prefix_properties:
if curly[:len(prop) + 1] == prop + ':':
for tag in self.prefix_tags:
new_data += ' -%s-%s; ' % (tag, curly)
new_data += curly + (' { ' if len(curl_split) > 1 else ' ')
new_data += '; '
new_data = new_data.replace('{ ;', '; ').replace('} ;', '} ')
return new_data

24
couchpotato/static/scripts/reloader.js

@ -1,24 +0,0 @@
var ReloaderBase = new Class({
initialize: function(){
var self = this;
App.on('watcher.changed', self.reloadFile.bind(self));
},
reloadFile: function(data){
var self = this,
urls = data.data;
urls.each(function(url){
var without_timestamp = url.split('?')[0],
old_links = document.getElement('[data-url^=\''+without_timestamp+'\']');
old_links.set('href', old_links.get('href') + 1);
});
}
});
var Reloader = new ReloaderBase();

20
couchpotato/templates/index.html

@ -2,7 +2,7 @@
<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="mobile-web-app-capable" content="yes">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
@ -21,22 +21,22 @@
<link rel="apple-touch-icon" href="{{ Env.get('static_path') }}images/homescreen.png" />
{% if Env.get('dev') %}
<script type="text/javascript" src="{{ Env.get('static_path') }}scripts/reloader.js"></script>
<script src="//localhost:35729/livereload.js?snipver=1"></script>
{% end %}
<script type="text/javascript" src="https://www.youtube.com/player_api" defer="defer"></script>
<script type="text/javascript" src="//www.youtube.com/player_api" defer="defer"></script>
<script type="text/javascript">
window.addEvent('load', function(){
window.addEvent('load', function(){
if(window.getSize().x <= 480)
setTimeout(function(){
window.scrollTo(0, 1);
window.scrollTo(0, 0);
}, 100);
if(window.getSize().x <= 480)
setTimeout(function(){
window.scrollTo(0, 1);
window.scrollTo(0, 0);
}, 100);
});
});
window.addEvent('domready', function() {

Loading…
Cancel
Save