6

I already had a project with .haml and .scss files in various folders.

I followed this guide here http://winstonyw.com/2013/02/24/jekyll_haml_sass_and_github_pages/ to create _plugins/haml.rb and _plugins/sass.rb

I moved all my .scss files into ./assets/css/ folder

To make sure, I also created layouts folder and put all .haml files in there.

I ran jekyll serve --watch and these .haml / .scss files didn't get converted to .html or .css files in _sites. I cannot access them via the browser either.

I tried this file here and didn't help either https://gist.github.com/radamant/481456#file-haml_converter-rb

So what did I do wrong and how to watch live all .haml / .scss files?

I came from middlemanapp world so jekyll is new to me.

UPDATE 1:

My high level goals are:

  1. Use Jekyll for frontend development with Sass and Haml

  2. It must watch for changes in files

  3. It must convert .sass / . scss files and Haml to .css and .html on watch. Meaning I could go to http://localhost:4000/index.html when in fact I have index.haml as Haml

  4. My project doesn't follow the directory structure said in Jekyll doc (with layouts folder and others). This must be able to detect .sass and .haml files in other folders (I can specify this)

  5. I don't want to modify any .sass or .scss files in the header to make Jekyll to detect it. Because I have tons of those (from Bootstrap) already

UPDATE 2:

Here is my new _config.yml

source:      .
destination: ./_site
plugins:     ./_plugins
layouts:     .

Basically I want to have all .haml files at the main folder, not layouts. In _plugins I have _plugins/haml.rb and _plugins/sass.rb as said above. Still, it doesn't work when I created a sample index1.haml in the main folder, it didn't get converted when --watch

UPDATE 3:

Here is my directory structure:

/www

 /_plugins

  haml.rb

  sass.rb

 /_layouts

  index1.haml

 _config.yml
 index1.haml

In haml.rb:

module Jekyll
  require 'haml'
  class HamlConverter < Converter
    safe true
    priority :low

    def matches(ext)
      ext =~ /haml/i
    end

    def output_ext(ext)
      ".html"
    end

    def convert(content)
      engine = Haml::Engine.new(content)
      engine.render
    rescue StandardError => e
      puts "!!! HAML Error: " + e.message
    end
  end
end

In index1.haml (both file has same content):

!!!
%html
  %head
    %meta{charset: "utf-8"}/
    %meta{content: "initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width", name: "viewport"}/
    %title
  %body
    Test Test

In _config.yaml

---
source:      .
destination: ./_site
plugins:     ./_plugins
layouts:     ./_layouts
---

This still doesn't work for me. No .html files generated.

UPDATE $:

Adding this to .haml files work:

---
title: Index
---

However, I can modify .haml files but I try to avoid doing that with .sass / .scss files. I have tons of them from Bootstrap and other work. Is there any workaround?

HP.
  • 19,226
  • 53
  • 154
  • 253
  • Can you post your _config.yml? Any `exclude` directives? `source` is set correctly? Can you place an html file in the source folder and see if that gets correctly processed? – bwest Jun 10 '14 at 18:01
  • I dont have `_config.yml` file in the folder. Is that an issue? – HP. Jun 10 '14 at 21:15
  • Yes, I think this is the source of your problem. See my answer :) – bwest Jun 10 '14 at 22:01

4 Answers4

2

It sounds like you don't have a proper Jekyll configuration specifying your source directory.

You can build things by specifying the config via parameters, like so: jekyll serve --source assets --destination public

But it's probably better to grab a _config.yml example and go from there. The very scenario you're facing is described in the Basic Usage docs.

Start with a very simple _config.yml containing:

source:      source
destination: public

Make sure that your _plugins and _layouts are children of the source directory.

If you don't create your own config, then a default config is used. If you want to use this config, make sure your structure and toolset matches it:

source:      .
destination: ./_site
plugins:     ./_plugins
layouts:     ./_layouts
include:     ['.htaccess']
exclude:     []
keep_files:  ['.git','.svn']
gems:        []
timezone:    nil
encoding:    nil

future:      true
show_drafts: nil
limit_posts: 0
highlighter: pygments

relative_permalinks: true

permalink:     date
paginate_path: 'page:num'
paginate:      nil

markdown:      kramdown
markdown_ext:  markdown,mkdown,mkdn,mkd,md
textile_ext:   textile

excerpt_separator: "\n\n"

safe:        false
watch:       false    # deprecated
server:      false    # deprecated
host:        0.0.0.0
port:        4000
baseurl:     ""
url:         http://localhost:4000
lsi:         false

maruku:
  use_tex:    false
  use_divs:   false
  png_engine: blahtex
  png_dir:    images/latex
  png_url:    /images/latex
  fenced_code_blocks: true

rdiscount:
  extensions: []

redcarpet:
  extensions: []

kramdown:
  auto_ids: true
  footnote_nr: 1
  entity_output: as_char
  toc_levels: 1..6
  smart_quotes: lsquo,rsquo,ldquo,rdquo
  use_coderay: false

  coderay:
    coderay_wrap: div
    coderay_line_numbers: inline
    coderay_line_numbers_start: 1
    coderay_tab_width: 4
    coderay_bold_every: 10
    coderay_css: style

redcloth:
  hard_breaks: true

You must also ensure that every page that you want to be processed by Jekyll has the appropriate YAML front-matter.

Any file that contains a YAML front matter block will be processed by Jekyll as a special file.

If you don't have that YAML front-matter, your plugins won't be applied.

It can even be empty, like

---
---

#haml

Delete ./_layouts/index1.haml you don't need it. Change index1.haml to this:

---
title: Index
---

!!!
%html
  %head
    %meta{charset: "utf-8"}/
    %meta{content: "initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width", name: "viewport"}/
    %title
  %body
    Test Test

And remove the --- lines from _config.yml -- it should be

source:      .
destination: ./_site
plugins:     ./_plugins
layouts:     ./_layouts

As far as I know, using a Jekyll plugin, there is not a way to process the .scss files without requiring the YAML front-matter in those files. To achieve this you need to use a preprocessor in addition to the jekyll processing. I personally use Jekyll Asset Pipeline Reborn. It's easy to setup and has some nice other features like minifying and stitching files together.

OR since you are using grunt (I assume, due to your tag) you could use grunt to preprocess your .scss.

bwest
  • 9,182
  • 3
  • 28
  • 58
  • I am still facing trouble. Please see my new update. – HP. Jun 10 '14 at 22:58
  • @HP. You can't have your `layouts` and your `source` be the same folder, jekyll won't know what is what. Change `layouts` back to a child folder, create some page e.g. `index.haml` in `.`, and try to generate your site. You don't need any layouts at all. – bwest Jun 10 '14 at 23:02
  • @HP. Please post the contents of one of your HAML files. Do you have the required YAML front matter? – bwest Jun 10 '14 at 23:06
  • Please see my update with this stubborn issue. Thanks. – HP. Jun 11 '14 at 22:27
  • You need to add the YAML to index1.haml. I'll update my answer – bwest Jun 11 '14 at 22:55
  • Okay, see the fixed versions of your `index1.haml` and `_config.yml` in my answer. – bwest Jun 11 '14 at 23:00
  • Work now. Thanks. Is there a way to avoid adding `---` to `.scss` files (UPDATE 1, #5)? I can deal with `.haml` as those are mine but `.scss` files mostly are from Bootstrap... :P – HP. Jun 11 '14 at 23:31
  • Glad you are having success now! Using a Jekyll plugin, there is not any way to process the `.scss` files without requiring the YAML front-matter in those files. To achieve this you need to use a preprocessor in addition to the jekyll processing. I personally use [Jekyll Asset Pipeline Reborn](https://github.com/kitsched/japr). It's easy to setup and has some nice other features like minifying and stitching files together. – bwest Jun 12 '14 at 01:09
  • @HP. I also added a note and a link on how to use grunt to handle this, since you tagged the question with grunt. – bwest Jun 12 '14 at 15:42
  • I tried to consolidate everything under Jekyll but look like it's lacking. In Middleman App I can do Haml and Sass watch but I prefer Jekyll only. Grunt Sass now is a separate task runner. I'm still trying to understand **Jekyll Asset Pipeline Reborn** on what it can do... – HP. Jun 12 '14 at 18:22
  • Spend some time exploring JAPR, it will solve your problem once you know how to implement it. In the meantime, I hope you will accept my answer since I believe I have answered everything you've asked for. If you need help with Jekyll Asset Pipeline and want to create questions specific to that I will help there as well. – bwest Jun 12 '14 at 19:27
0

I've had success using fssm & listen for various precompilers that i wanted outside of my asset pipeline:

https://github.com/guard/listen

https://rubygems.org/gems/fssm

Both will watch directories for file changes, and then execute commands when a change is detected. You can hook up your compilers to run on these events.

Jack Murphy
  • 2,952
  • 1
  • 30
  • 49
-1

HP, have you tried using the Jekyll::HAML gem from samvincent? Find the project here:

https://github.com/samvincent/jekyll-haml

It's pretty simple to setup. Make a _plugins folder in your project's root directory (looks like you already did), then make an .rb file that requires the following:

require "rubygems"
require "bundler/setup"
Bundler.require(:default)

Should convert the HAML when you build the page.

  • 1
    This is strange because it still doesn't work. The _site folder still has .haml files and .scss files unconverted. What did I miss? – HP. Jun 06 '14 at 07:45
-1

Good news anyone coming to this page these days, looks like HAML's supported out the box in the latest version of Jekyll! Just change your file name to .haml, and you should be GTG