Permalink
Browse files

Merge pull request #85 from blueyed/master

Mainly revert "--filetype" change (fix it properly) and some more
  • Loading branch information...
2 parents 615f1c8 + 6b7e387 commit d949ff782ecf9c4b2b778b217231caeb5c18930b @faceleg faceleg committed Oct 8, 2013
Showing with 41 additions and 31 deletions.
  1. +5 −2 Makefile
  2. +12 −19 sparkup.py
  3. +23 −10 vim/ftplugin/html/sparkup.vim
  4. +1 −0 vim/ftplugin/smarty
View
7 Makefile
@@ -1,4 +1,7 @@
-SPARKUP_PY=sparkup
+# Makefile for sparkup distribution
+# TODO: this should use a separate build dir to copy SPARKUP_PY into.
+# SPARKUP_PY should not reside in the Vim runtime dir (getting not updated via Git!)
+SPARKUP_PY=sparkup.py
VERSION=`date '+%Y%m%d'`
README=README.md
@@ -24,7 +27,7 @@ all-dist:
cp distribution/sparkup-${VERSION}.zip distribution/sparkup-latest.zip
generic:
- cat sparkup.py > generic/sparkup
+ cat ${SPARKUP_PY} > generic/sparkup
chmod +x generic/sparkup
#cp ${README} generic/sparkup-readme.txt
View
31 sparkup.py 100644 → 100755
@@ -1,5 +1,7 @@
-import os
-import fileinput
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+version = "0.1.3"
+
import getopt
import sys
import re
@@ -13,13 +15,10 @@ class Dialect:
short_tags = ()
class XmlDialect(Dialect):
- shortcuts = {
- }
- synonyms = {
- }
+ shortcuts = {}
+ synonyms = {}
short_tags = ()
- required = {
- }
+ required = {}
class HtmlDialect(Dialect):
# TODO: the indentation in snippets should also be based on the user's
@@ -298,7 +297,7 @@ def __init__(self, options=None, str=''):
self.tokens = []
self.str = str
self.options = options
- if self.options.has("filetype") and self.options.get("filetype") == "xml":
+ if self.options.has("xml"):
self.dialect = XmlDialect()
else:
self.dialect = HtmlDialect()
@@ -538,7 +537,7 @@ def __init__(self, token=None, parent=None, count=None, local_count=None, \
self.attributes[key] = attrib
# Copy over from parameters
- if attributes: self.attributes = attribues
+ if attributes: self.attributes = attributes
if name: self.name = name
if text: self.text = text
@@ -551,9 +550,9 @@ def __init__(self, token=None, parent=None, count=None, local_count=None, \
if self.populate: self._populate()
def render(self):
- """renders the element, along with it's subelements, into html code.
+ """Renders the element, along with it's subelements, into HTML code.
- [grouped under "rendering methods"]
+ [Grouped under "Rendering methods"]
"""
output = ""
@@ -853,10 +852,6 @@ def _init_element(self):
name = synonyms[name]
if ':' in name:
- try: spaces_count = int(self.parser.options.get('indent-spaces'))
- except: spaces_count = 4
- indent = ' ' * spaces_count
-
shortcuts = self.parser.dialect.shortcuts
if name in shortcuts.keys():
for key, value in shortcuts[name].iteritems():
@@ -991,7 +986,6 @@ def parse(self, str=None, ret=None):
try:
# Read the files
- # for line in fileinput.input(): lines.append(line.rstrip(os.linesep))
if str is not None:
lines = str
else:
@@ -1053,7 +1047,6 @@ def __init__(self, router, argv, options=None):
# Sort them out into options
options = {}
- i = 0
for option in getoptions:
key, value = option # '--version', ''
if (value == ''): value = True
@@ -1091,7 +1084,6 @@ def has(self, attr):
cmdline_keys = [
('h', 'help', 'Shows help'),
('v', 'version', 'Shows the version'),
- ('', 'filetype=', 'enable html attribute fillings unless filetype=xml'),
('', 'no-guides', 'Deprecated'),
('', 'post-tag-guides', 'Adds comments at the end of DIV tags'),
('', 'textmate', 'Adds snippet info (textmate mode)'),
@@ -1101,6 +1093,7 @@ def has(self, attr):
('', 'no-last-newline', 'Skip the trailing newline'),
('', 'start-guide-format=', 'To be documented'), # << TODO
('', 'end-guide-format=', 'To be documented'), # << TODO
+ ('', 'xml', 'Skip html attribute fillings'),
('', 'no-html5-self-closing', 'Use HTML4 <br /> instead of HTML5 <br>'),
]
View
33 vim/ftplugin/html/sparkup.vim
@@ -67,12 +67,11 @@ endif
function! s:Sparkup()
if !exists('s:sparkup')
let s:sparkup = exists('g:sparkup') ? g:sparkup : 'sparkup'
- let s:sparkupArgs = exists('g:sparkupArgs') ? g:sparkupArgs : '--no-last-newline'
- let s:sparkupArgs = s:sparkupArgs . ' --filetype=' . &filetype
- " check the user's path first. if not found then search relative to
- " sparkup.vim in the runtimepath.
if !executable(s:sparkup)
+ " If g:sparkup is not configured (and/or not found in $PATH),
+ " look for sparkup.vim in Vim's runtimepath.
+ " XXX: quite expensive for a Pathogen-like environment (where &rtp is huge)
let paths = substitute(escape(&runtimepath, ' '), '\(,\|$\)', '/**\1', 'g')
let s:sparkup = fnamemodify(findfile('sparkup.py', paths), ':p')
@@ -85,14 +84,28 @@ function! s:Sparkup()
endif
endif
let s:sparkup = '"' . s:sparkup . '"'
- let s:sparkup .= printf(' %s --indent-spaces=%s', s:sparkupArgs, &shiftwidth)
- " If the user's settings are to indent with tabs, do so!
- " TODO textmate version of this functionality
- if !&expandtab
- let s:sparkup .= ' --indent-tabs'
+ " Workaround for windows, where the Python file cannot be executed via shebang
+ if has('win32') || has('win64')
+ let s:sparkup = 'python ' . s:sparkup
endif
endif
- exec '.!python ' . s:sparkup
+
+ " Build arguments list (not cached, g:sparkupArgs might change, also
+ " &filetype, &expandtab etc)
+ let sparkupArgs = exists('g:sparkupArgs') ? g:sparkupArgs : '--no-last-newline'
+ " Pass '--xml' option, if 'xml' is used as filetype (default: none/'html')
+ " NOTE: &filetype can contain multiple values, e.g. 'smarty.html'
+ if index(split(&filetype, '\.'), 'xml') >= 0
+ let sparkupArgs .= ' --xml'
+ endif
+ " If the user's settings are to indent with tabs, do so!
+ " TODO textmate version of this functionality
+ if !&expandtab
+ let sparkupArgs .= ' --indent-tabs'
+ endif
+
+ let sparkupCmd = s:sparkup . printf(' %s --indent-spaces=%s', sparkupArgs, &shiftwidth)
+ exec '.!' . sparkupCmd
call s:SparkupNext()
endfunction
View
1 vim/ftplugin/smarty

0 comments on commit d949ff7

Please sign in to comment.