Skip to content

Commit 8453f78

Browse files
committed
Initial Commit
0 parents  commit 8453f78

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed

Default (OSX).sublime-keymap

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[
2+
{ "keys": ["super+shift+c"], "command": "concat" }
3+
]

README.md

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#SublimeConcat
2+
3+
Automatically concatenate all of the dependencies in the current file
4+
5+
## Usage:
6+
7+
Define the dependencies using the @import syntax
8+
9+
CSS:
10+
11+
@import url('bootstrap.min.css');
12+
13+
body { background-color: #fff; }
14+
15+
JS:
16+
17+
//@import url('jquery.min.js');
18+
19+
$(document).ready(function(){
20+
console.log('ready');
21+
});
22+
23+
`Command + Shift + C` will concatenate all of the dependences into a new file: `{{filename}}.cat.{{extension}}`
24+
25+
Use with [YUI Compressor](https://github.com/leon/YUI-Compressor) and [SublimeOnSaveBuild](https://github.com/alexnj/SublimeOnSaveBuild) for automatic concat and minify

concat.py

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import sublime_plugin
2+
import sublime
3+
import re
4+
5+
6+
class ConcatCommand(sublime_plugin.TextCommand):
7+
def run(self, edit):
8+
view = self.view
9+
window = view.window()
10+
region = sublime.Region(0, view.size())
11+
12+
path = '/'.join(self.view.file_name().split('/')[0:-1])
13+
full_name = self.view.file_name().split('/')[-1]
14+
extension = full_name.split('.')[-1]
15+
file_name = '.'.join(full_name.split('.')[0:-1])
16+
17+
test = '/{0,2}@import url\(\'(.+)\'\);'
18+
i = self.view.find(test, 0)
19+
if i:
20+
new_view = window.new_file()
21+
new_view.set_name(file_name + '.cat.' + extension)
22+
region = sublime.Region(0, view.size())
23+
content = view.substr(region)
24+
25+
try:
26+
syntax_file = self.view.settings().get('syntax')
27+
new_view.set_syntax_file(syntax_file)
28+
except KeyError:
29+
print 'no syntax'
30+
pass
31+
32+
edit = new_view.begin_edit('cat')
33+
new_view.insert(edit, 0, content)
34+
35+
while new_view.find(test, 0):
36+
i = new_view.find(test, 0)
37+
content = new_view.substr(i)
38+
m = re.search(test, content)
39+
40+
if m:
41+
included = m.group(1)
42+
43+
try:
44+
f = open(path + '/' + included)
45+
file_content = f.read()
46+
new_view.replace(edit, i, file_content)
47+
f.close()
48+
except IOError:
49+
print 'cannot open', included
50+
raise
51+
52+
new_view.end_edit(edit)
53+
window.run_command("save")
54+
window.run_command("build")

0 commit comments

Comments
 (0)