redcar-sparkup 1.0 → 1.01

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,79 @@
1
+ " Sparkup
2
+ " Installation:
3
+ " Copy the contents of vim/ftplugin/ to your ~/.vim/ftplugin directory.
4
+ "
5
+ " $ cp -R vim/ftplugin ~/.vim/ftplugin/
6
+ "
7
+ " Configuration:
8
+ " g:sparkup (Default: 'sparkup') -
9
+ " Location of the sparkup executable. You shouldn't need to change this
10
+ " setting if you used the install option above.
11
+ "
12
+ " g:sparkupArgs (Default: '--no-last-newline') -
13
+ " Additional args passed to sparkup.
14
+ "
15
+ " g:sparkupExecuteMapping (Default: '<c-e>') -
16
+ " Mapping used to execute sparkup.
17
+ "
18
+ " g:sparkupNextMapping (Default: '<c-n>') -
19
+ " Mapping used to jump to the next empty tag/attribute.
20
+
21
+ if !exists('g:sparkupExecuteMapping')
22
+ let g:sparkupExecuteMapping = '<c-e>'
23
+ endif
24
+
25
+ if !exists('g:sparkupNextMapping')
26
+ let g:sparkupNextMapping = '<c-n>'
27
+ endif
28
+
29
+ imap <buffer> <Plug>SparkupExecute <c-g>u<Esc>:call <SID>Sparkup()<cr>
30
+ imap <buffer> <Plug>SparkupNext <c-g>u<Esc>:call <SID>SparkupNext()<cr>
31
+
32
+ if ! hasmapto('<Plug>SparkupExecute', 'i')
33
+ exec 'imap <buffer> ' . g:sparkupExecuteMapping . ' <Plug>SparkupExecute'
34
+ endif
35
+ if ! hasmapto('<Plug>SparkupNext', 'i')
36
+ exec 'imap <buffer> ' . g:sparkupNextMapping . ' <Plug>SparkupNext'
37
+ endif
38
+
39
+ if exists('*s:Sparkup')
40
+ finish
41
+ endif
42
+
43
+ function! s:Sparkup()
44
+ if !exists('s:sparkup')
45
+ let s:sparkup = exists('g:sparkup') ? g:sparkup : 'sparkup'
46
+ let s:sparkupArgs = exists('g:sparkupArgs') ? g:sparkupArgs : '--no-last-newline'
47
+ " check the user's path first. if not found then search relative to
48
+ " sparkup.vim in the runtimepath.
49
+ if !executable(s:sparkup)
50
+ let paths = substitute(escape(&runtimepath, ' '), '\(,\|$\)', '/**\1', 'g')
51
+ let s:sparkup = findfile('sparkup.py', paths)
52
+
53
+ if !filereadable(s:sparkup)
54
+ echohl WarningMsg
55
+ echom 'Warning: could not find sparkup on your path or in your vim runtime path.'
56
+ echohl None
57
+ finish
58
+ endif
59
+ endif
60
+ let s:sparkup = '"' . s:sparkup . '"'
61
+ let s:sparkup .= printf(' %s --indent-spaces=%s', s:sparkupArgs, &shiftwidth)
62
+ if has('win32') || has('win64')
63
+ let s:sparkup = 'python ' . s:sparkup
64
+ endif
65
+ endif
66
+ exec '.!' . s:sparkup
67
+ call s:SparkupNext()
68
+ endfunction
69
+
70
+ function! s:SparkupNext()
71
+ " 1: empty tag, 2: empty attribute, 3: empty line
72
+ let n = search('><\/\|\(""\)\|^\s*$', 'Wp')
73
+ if n == 3
74
+ startinsert!
75
+ else
76
+ execute 'normal l'
77
+ startinsert
78
+ endif
79
+ endfunction
data/lib/sparkup.rb ADDED
@@ -0,0 +1,115 @@
1
+ module Redcar
2
+ class Sparkup
3
+
4
+ def self.plugin_dir
5
+ File.join(File.dirname(__FILE__), "..")
6
+ end
7
+
8
+ attr_accessor :indent_spaces
9
+
10
+ # Default sparkup command, if OS has Python
11
+ @@sparkup_cmd = ""
12
+
13
+ def initialize
14
+ self.indent_spaces = self.class.get_indent_value
15
+ @@sparkup_cmd = "#{Sparkup.plugin_dir}/assets/sparkup/sparkup --indent-spaces=#{self.indent_spaces}"
16
+
17
+ # Set the menu item
18
+ self.class.menus
19
+
20
+ # Set the keybindings
21
+ # TODO: Make the keybindings as a preference
22
+ self.class.keymaps
23
+
24
+ # Jython fallback if Python isn't installed
25
+ unless self.class.hasPython
26
+ @@sparkup_cmd = "java -jar #{Sparkup.plugin_dir}/jython/jython.jar #{Sparkup.plugin_dir}/assets/sparkup/sparkup --indent-spaces=#{self.indent_spaces}"
27
+ end
28
+ end
29
+
30
+ def self.get_indent_value
31
+ win = Redcar.app.focussed_window
32
+ tab = win.focussed_notebook.focussed_tab
33
+ tab.edit_view.tab_width
34
+ end
35
+
36
+ # Get Sparkup's cmd
37
+ def getCmd
38
+ @@sparkup_cmd
39
+ end
40
+
41
+ # Shows the menu in the toolbar
42
+ def self.menus
43
+ Redcar::Menu::Builder.build do
44
+ sub_menu "Plugins" do
45
+ sub_menu "Sparkup" do
46
+ item "Sparkup line", SparkupLine
47
+ item "Edit Sparkup", EditSparkup
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+ # Makes the keybindings
54
+ def self.keymaps
55
+ map = Redcar::Keymap.build("main", [:osx, :linux, :windows]) do
56
+ link "Ctrl+Shift+D", SparkupLine
57
+ end
58
+ [map]
59
+ end
60
+
61
+ # Check if Python is installed
62
+ def self.hasPython
63
+
64
+ if Redcar.platform == :windows
65
+
66
+ # I haven't found a useable python test
67
+ # Got any? Send them to me pls
68
+ return false
69
+ else
70
+
71
+ pTest = `which python`
72
+ return pTest != ''
73
+ end
74
+ end
75
+
76
+ # Open Sparkup's file (this) for edit
77
+ class EditSparkup < Redcar::Command
78
+ def execute
79
+
80
+ Project::Manager.open_project_for_path(
81
+ File.join(File.dirname(__FILE__), "..")
82
+ )
83
+
84
+ tab = Redcar.app.focussed_window.new_tab(Redcar::EditTab)
85
+ mirror = Project::FileMirror.new(File.join(
86
+ File.join(Sparkup.plugin_dir, "lib", "sparkup.rb")
87
+ ))
88
+ tab.edit_view.document.mirror = mirror
89
+ tab.edit_view.reset_undo
90
+ tab.focus
91
+ end
92
+ end
93
+
94
+ # Run Sparkup
95
+ class SparkupLine < EditTabCommand
96
+ def execute
97
+ doc.replace_line(doc.cursor_line) do |ltext|
98
+ spark = Sparkup.new
99
+ cmd = spark.getCmd
100
+ dir = "#{Sparkup.plugin_dir}/assets"
101
+ startLine = doc.cursor_offset
102
+
103
+ # Run the command
104
+ cmd = "cd #{dir} && echo '#{ltext}' | #{cmd}"
105
+ resp = `#{cmd}`
106
+
107
+ # Set the cursor to the start of the line
108
+ # TODO: Add tab positions like snippets
109
+ doc.cursor_offset = startLine
110
+ resp
111
+ end
112
+ end
113
+ end
114
+ end
115
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redcar-sparkup
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.0'
4
+ version: '1.01'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-09-13 00:00:00.000000000Z
13
+ date: 2011-09-14 00:00:00.000000000Z
14
14
  dependencies: []
15
15
  description: ''
16
16
  email:
@@ -19,6 +19,20 @@ executables: []
19
19
  extensions: []
20
20
  extra_rdoc_files: []
21
21
  files:
22
+ - lib/sparkup.rb
23
+ - assets/jython/jython.jar
24
+ - assets/sparkup/Makefile
25
+ - assets/sparkup/mit-license.txt
26
+ - assets/sparkup/README.md
27
+ - assets/sparkup/sparkup
28
+ - assets/sparkup/sparkup-unittest.py
29
+ - assets/sparkup/sparkup.py
30
+ - assets/sparkup/TextMate/Sparkup.tmbundle/Commands/Sparkup expand.tmCommand
31
+ - assets/sparkup/TextMate/Sparkup.tmbundle/info.plist
32
+ - assets/sparkup/TextMate/Sparkup.tmbundle/Support/sparkup.py
33
+ - assets/sparkup/vim/ftplugin/html/sparkup.py
34
+ - assets/sparkup/vim/ftplugin/html/sparkup.vim
35
+ - assets/sparkup/vim/README.txt
22
36
  - README.md
23
37
  - plugin.rb
24
38
  homepage: http://github.com/agmcleod/redcar-sparkup