Commits

Alessandro Molina committed 34162b4

Adapt SCSS inclusion path for tg-bootstrap

Comments (0)

Files changed (1)

gearboxtools/tgbootstrap/command.py

 
 BOOTSTRAP = '''  <link rel="stylesheet" type="text/css" media="screen" href="${tg.url('/bootstrap/stylesheets/bootstrap.scss')}" />\n'''
 BOOTSTRAP_RESPONSIVE = '''  <link rel="stylesheet" type="text/css" media="screen" href="${tg.url('/bootstrap/stylesheets/bootstrap-responsive.scss')}" />\n'''
+APPEND_PATH = '''
+def append_boostrap_include_path(app):
+    import tg, os
+
+    include_path = tg.config.get('tgext.scss.include_paths')
+    if include_path:
+        if isinstance(include_path, str):
+            include_path.split(',')
+    else:
+        include_path = tg.config['tgext.scss.include_paths'] = []
+
+    basepath = os.path.normcase(os.path.abspath((tg.config['paths']['static_files'])))
+    include_path.append(basepath + '%(include_path)s')
+
+    return app
+base_config.register_hook('before_config', append_boostrap_include_path)
+'''
 
 class TGBootstrapCommand(TemplateCommand):
     def get_description(self):
             config_content = '\n'.join([config_content, "plug(base_config, 'tgext.scss')"])
             return config_content
 
+    def _append_scss_include_path(self, app_config):
+        with contextlib.closing(open(app_config)) as config:
+            config_content = config.read()
+            if 'public/bootstrap/stylesheets' in config_content:
+                return config_content
+
+            append_path_content = APPEND_PATH % dict(include_path='/bootstrap/stylesheets')
+            config_content = '\n'.join([config_content, append_path_content])
+            return config_content
+
     def take_action(self, opts):
         if not os.path.exists('development.ini'):
             log.error('Must be run inside a TurboGears2 project')
 
         master_templates = self._find_master_templates(project_dir)
         for master_template in master_templates:
+            log.info('Patching %s template', master_template)
             master = self._replace_css_links(master_template)
             with contextlib.closing(open(master_template, 'w')) as template_file:
                 template_file.write(master)
         app_cfg = self._find_app_config(project_dir)
         new_config = self._append_scss_plug(app_cfg)
         with contextlib.closing(open(app_cfg, 'w')) as config:
-            config.write(new_config)
+            log.info('Plugging tgext.scss')
+            config.write(new_config)
+
+        new_config = self._append_scss_include_path(app_cfg)
+        with contextlib.closing(open(app_cfg, 'w')) as config:
+            log.info('Tuning SCSS include path')
+            config.write(new_config)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.