Skip to content

Commit

Permalink
Merge pull request #85 from blueyed/master
Browse files Browse the repository at this point in the history
Mainly revert "--filetype" change (fix it properly) and some more
  • Loading branch information
faceleg committed Oct 8, 2013
2 parents 615f1c8 + 6b7e387 commit d949ff7
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 31 deletions.
7 changes: 5 additions & 2 deletions Makefile
Original file line number Original file line Diff line number Diff line change
@@ -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'` VERSION=`date '+%Y%m%d'`
README=README.md README=README.md


Expand All @@ -24,7 +27,7 @@ all-dist:
cp distribution/sparkup-${VERSION}.zip distribution/sparkup-latest.zip cp distribution/sparkup-${VERSION}.zip distribution/sparkup-latest.zip


generic: generic:
cat sparkup.py > generic/sparkup cat ${SPARKUP_PY} > generic/sparkup
chmod +x generic/sparkup chmod +x generic/sparkup
#cp ${README} generic/sparkup-readme.txt #cp ${README} generic/sparkup-readme.txt


Expand Down
31 changes: 12 additions & 19 deletions sparkup.py
100644 → 100755
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,7 @@
import os #!/usr/bin/env python
import fileinput # -*- coding: utf-8 -*-
version = "0.1.3"

import getopt import getopt
import sys import sys
import re import re
Expand All @@ -13,13 +15,10 @@ class Dialect:
short_tags = () short_tags = ()


class XmlDialect(Dialect): class XmlDialect(Dialect):
shortcuts = { shortcuts = {}
} synonyms = {}
synonyms = {
}
short_tags = () short_tags = ()
required = { required = {}
}


class HtmlDialect(Dialect): class HtmlDialect(Dialect):
# TODO: the indentation in snippets should also be based on the user's # TODO: the indentation in snippets should also be based on the user's
Expand Down Expand Up @@ -298,7 +297,7 @@ def __init__(self, options=None, str=''):
self.tokens = [] self.tokens = []
self.str = str self.str = str
self.options = options self.options = options
if self.options.has("filetype") and self.options.get("filetype") == "xml": if self.options.has("xml"):
self.dialect = XmlDialect() self.dialect = XmlDialect()
else: else:
self.dialect = HtmlDialect() self.dialect = HtmlDialect()
Expand Down Expand Up @@ -538,7 +537,7 @@ def __init__(self, token=None, parent=None, count=None, local_count=None, \
self.attributes[key] = attrib self.attributes[key] = attrib


# Copy over from parameters # Copy over from parameters
if attributes: self.attributes = attribues if attributes: self.attributes = attributes
if name: self.name = name if name: self.name = name
if text: self.text = text if text: self.text = text


Expand All @@ -551,9 +550,9 @@ def __init__(self, token=None, parent=None, count=None, local_count=None, \
if self.populate: self._populate() if self.populate: self._populate()


def render(self): 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 = "" output = ""
Expand Down Expand Up @@ -853,10 +852,6 @@ def _init_element(self):
name = synonyms[name] name = synonyms[name]


if ':' in 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 shortcuts = self.parser.dialect.shortcuts
if name in shortcuts.keys(): if name in shortcuts.keys():
for key, value in shortcuts[name].iteritems(): for key, value in shortcuts[name].iteritems():
Expand Down Expand Up @@ -991,7 +986,6 @@ def parse(self, str=None, ret=None):


try: try:
# Read the files # Read the files
# for line in fileinput.input(): lines.append(line.rstrip(os.linesep))
if str is not None: if str is not None:
lines = str lines = str
else: else:
Expand Down Expand Up @@ -1053,7 +1047,6 @@ def __init__(self, router, argv, options=None):


# Sort them out into options # Sort them out into options
options = {} options = {}
i = 0
for option in getoptions: for option in getoptions:
key, value = option # '--version', '' key, value = option # '--version', ''
if (value == ''): value = True if (value == ''): value = True
Expand Down Expand Up @@ -1091,7 +1084,6 @@ def has(self, attr):
cmdline_keys = [ cmdline_keys = [
('h', 'help', 'Shows help'), ('h', 'help', 'Shows help'),
('v', 'version', 'Shows the version'), ('v', 'version', 'Shows the version'),
('', 'filetype=', 'enable html attribute fillings unless filetype=xml'),
('', 'no-guides', 'Deprecated'), ('', 'no-guides', 'Deprecated'),
('', 'post-tag-guides', 'Adds comments at the end of DIV tags'), ('', 'post-tag-guides', 'Adds comments at the end of DIV tags'),
('', 'textmate', 'Adds snippet info (textmate mode)'), ('', 'textmate', 'Adds snippet info (textmate mode)'),
Expand All @@ -1101,6 +1093,7 @@ def has(self, attr):
('', 'no-last-newline', 'Skip the trailing newline'), ('', 'no-last-newline', 'Skip the trailing newline'),
('', 'start-guide-format=', 'To be documented'), # << TODO ('', 'start-guide-format=', 'To be documented'), # << TODO
('', 'end-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>'), ('', 'no-html5-self-closing', 'Use HTML4 <br /> instead of HTML5 <br>'),
] ]


Expand Down
33 changes: 23 additions & 10 deletions vim/ftplugin/html/sparkup.vim
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -67,12 +67,11 @@ endif
function! s:Sparkup() function! s:Sparkup()
if !exists('s:sparkup') if !exists('s:sparkup')
let s:sparkup = exists('g:sparkup') ? g:sparkup : '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 !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 paths = substitute(escape(&runtimepath, ' '), '\(,\|$\)', '/**\1', 'g')
let s:sparkup = fnamemodify(findfile('sparkup.py', paths), ':p') let s:sparkup = fnamemodify(findfile('sparkup.py', paths), ':p')


Expand All @@ -85,14 +84,28 @@ function! s:Sparkup()
endif endif
endif endif
let s:sparkup = '"' . s:sparkup . '"' let s:sparkup = '"' . s:sparkup . '"'
let s:sparkup .= printf(' %s --indent-spaces=%s', s:sparkupArgs, &shiftwidth) " Workaround for windows, where the Python file cannot be executed via shebang
" If the user's settings are to indent with tabs, do so! if has('win32') || has('win64')
" TODO textmate version of this functionality let s:sparkup = 'python ' . s:sparkup
if !&expandtab
let s:sparkup .= ' --indent-tabs'
endif endif
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() call s:SparkupNext()
endfunction endfunction


Expand Down
1 change: 1 addition & 0 deletions vim/ftplugin/smarty

0 comments on commit d949ff7

Please sign in to comment.