Skip to content

Commit

Permalink
working copy
Browse files Browse the repository at this point in the history
  • Loading branch information
stephnr committed Jan 24, 2015
1 parent 5c8b722 commit 30c888f
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 166 deletions.
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# Sass-Director for Sublime

# sass-director-sublime
A port of Sass Director for Sublime

[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/Stephn-R/sass-director-sublime?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

Please visit the original Web Project by Una Kravet [HERE](https://github.com/una/sass-director)!

## Installation
Expand Down Expand Up @@ -38,6 +35,6 @@ Alternatively, you can clone the repository directly from GitHub into your Packa

## Future work

If any issues do appear, do not hesitate to report them under our [Issues](https://github.com/Stephn-R/sass-director-sublime/issues)
This Project was built upon ST3. Therefore, I have not validated with ST2 yet. If any issues do appear, do not hesitate to report them under our [Issues](https://github.com/Stephn-R/sass-director-sublime/issues)

##### And as always ~~ Happy Hacking!
252 changes: 108 additions & 144 deletions sass-director.py
Original file line number Diff line number Diff line change
@@ -1,144 +1,108 @@
import os
import re
import sublime
import platform
import sublime_plugin

watch_threads = []

class SassDirectorBase(sublime_plugin.WindowCommand):
fileExt = ""
root_path = ""
manifest_path = ""
manifest_file = ""
strip_list = [';', '@import', '\'', '\"']

def _buildPaths(self):
"""
@function: buildPaths
@description: Defines the Root Path and Files/Directories in the Root
"""
folders = self.window.folders()
view = self.window.active_view()

self.root_path = folders[0]
self.manifest_file = view.file_name()

self.fileExt = \
'.scss' if view.file_name().rfind(".scss") >= 0 else '.sass'

if(platform.system() is "Windows"):
self.manifest_path = \
self.manifest_file[:self.manifest_file.rfind('\\')]
else:
self.manifest_path = \
self.manifest_file[:self.manifest_file.rfind('/')]

def _stripImport(self, line):
"""
@function: pruneImport
@parameters: line: {str}
@description: Removes unnecessary information from the line
"""
for delimeter in self.strip_list:
line = line.replace(delimeter, '')
return line.strip()

@staticmethod
def _expandImports(imports):
"""
@function: expandImports
@parameters: imports: {List}
@description: Expands the list of imports into an array of strings.
Each entry in the array is like follows:
['{root_folder}', '{folder_in_root_folder}', ... , 'filename']
"""
paths = []
for e in imports:
path = [e.split('/') if '/' in e else e.split('\\')][0]
paths.append(path)
return paths

def _generateDirectories(self, dirs, view):
# Each entry is a directory structure
print(dirs)
for d in dirs:
file_name = '_' + d.pop(len(d)-1)
os.chdir(self.manifest_path)
for directory in d:
if directory not in os.listdir('.'):
os.mkdir(directory)
os.chdir(directory)
print("Made directory:", directory)
print("Now at:", end="")
print(os.path.dirname(os.path.realpath(__file__)))
else:
os.chdir(directory)
print("WARNING: Directory already exists")
os.chdir(self.manifest_path)
[os.chdir(directory) for directory in d]
# Change to associated directory
f = open(file_name + self.fileExt, 'w')
print("Wrote new scss file:", file_name + self.fileExt)
f.close()

def generateSassFromManifest(self):
self._buildPaths()

view = self.window.active_view()
body = view.substr(sublime.Region(0, view.size()))
lines = body.split('\n')

imports = []
# Grab Import Lines
for line in lines:
if re.match('^@import', line):
imports.append(self._stripImport(line))
dirs = self._expandImports(imports)
self._generateDirectories(dirs, view)
print("Done! Refreshing folder list...")
view.run_command('refresh_folder_list')

# ================================================
# ================== Commands ====================
# ================================================


class SassDirectorGenerateCommand(SassDirectorBase):
def run(self):
self.generateSassFromManifest()


class SassDirectorKillWatchCommand(SassDirectorBase):
def run


class SassDirectorWatchCommand(SassDirectorBase):
def run(self):
'''
#####################################################################
# In order to watch the files via the manifest,
we need to perform the following:
>> Ask the user to select folder for CSS export
1. Import the Subprocess module
2. Begin a new shell (automatically selects native shell)
3. Navigate to the directory containing this file
4. Execute 'sass -w manifest.scss:{End Folder}
5. Save the running process to the global watch_threads array as:
{ "shell": p, "filename": "{{ manifest_file_name }}" }
- Continue until user executes KillWatch command
######################################################################
'''
# Perform OS check for Bash vs. Cmd commands to execute
sh = subprocess.Popen(
"dir",
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)

# ================================================
# ================================================
import os
import re
import sublime
import platform
import sublime_plugin


class SassDirectorBase(sublime_plugin.WindowCommand):
root_path = ""
manifest_path = ""
manifest_file = ""
strip_list = [';', '@import', '\'', '\"']

def buildPaths(self):
"""
@function: buildPaths
@description: Defines the Root Path and Files/Directories in the Root
"""
folders = self.window.folders()
view = self.window.active_view()

self.root_path = folders[0]
self.manifest_file = view.file_name()

if(platform.system() is "Windows"):
self.manifest_path = \
self.manifest_file[:self.manifest_file.rfind('\\')]
else:
self.manifest_path = \
self.manifest_file[:self.manifest_file.rfind('/')]

def stripImport(self, line):
"""
@function: pruneImport
@parameters: line: {str}
@description: Removes unnecessary information from the line
"""
for delimeter in self.strip_list:
line = line.replace(delimeter, '')
return line.strip()

@staticmethod
def expandImports(imports):
"""
@function: expandImports
@parameters: imports: {List}
@description: Expands the list of imports into an array of strings.
Each entry in the array is like follows:
['{root_folder}', '{folder_in_root_folder}', ... , 'filename']
"""
paths = []
for e in imports:
path = [e.split('/') if '/' in e else e.split('\\')][0]
paths.append(path)
return paths

def generateDirectories(self, dirs, view):
# Each entry is a directory structure
print(dirs)
for d in dirs:
file_name = '_' + d.pop(len(d)-1)
os.chdir(self.manifest_path)
for directory in d:
if directory not in os.listdir('.'):
os.mkdir(directory)
os.chdir(directory)
print("Made directory:", directory)
print("Now at:", end="")
print(os.path.dirname(os.path.realpath(__file__)))
else:
os.chdir(directory)
print("WARNING: Directory already exists")
os.chdir(self.manifest_path)
[os.chdir(directory) for directory in d]
# Change to associated directory
f = open(file_name + '.scss', 'w')
print("Wrote new scss file:", file_name)
f.close()

def generateSassFromManifest(self):
self.buildPaths()

view = self.window.active_view()
body = view.substr(sublime.Region(0, view.size()))
lines = body.split('\n')

imports = []
# Grab Import Lines
for line in lines:
if re.match('^@import', line):
imports.append(self.stripImport(line))
dirs = self.expandImports(imports)
self.generateDirectories(dirs, view)
print("Done! Refreshing folder list...")
view.run_command('refresh_folder_list')

# ================================================
# ================== Commands ====================
# ================================================


class SassDirectorGenerateCommand(SassDirectorBase):
def run(self):
self.generateSassFromManifest()


# ================================================
# ================================================
17 changes: 0 additions & 17 deletions scss/sample-manifest.sass

This file was deleted.

0 comments on commit 30c888f

Please sign in to comment.