link_to vs. a
It is always comforting to find something on the internet about a problem you are having. If you have run into data attribute names getting mangled like I did then feel better, you are not alone. I was writing some javascript to hook into an <a>
tag that had data-user_id="1"
on it and things were not working. I did not understand what was happening since the same javascript and data attribute name was working on another <a>
tag on the same page. The difference was that one link was being generated with a haml %a
tag and the non working one with the rails helper link_to
. What was happening was the <a>
tag would create the data attributes with the exact name I gave them, user_id in this case, while the link_to
was trying to normalize my data name to be user-id. The javascript looked like:
Which of course would not find an attribute with the name user-id. On top of it jquery was doing some magic to turn the id into userId.
TLDR:
- Always name data attributes in html elements
data-your-name
, not data-your_name
.
- Beware of
link_to
, no idea what other magic this thing is performing.
Jekyll, Grunt And Bower Walk Into A Bar
I’m sure there’s some clever punchline to that and I hope I can come up with it before I’m done writing. I recently decided to use github pages to do my online writing. I have a couple of projects I’d like to do and share what I learned. I’ve been phone screening a lot of people at work and for some reason I enjoy asking them to build an elevator system to handle a hotel with 3 elevators and 20 floors that gets people where they’re going in the most efficient way. I’ll soon eat my own ducks in a row and code it, stay tuned.
The things I decided to use for my online writing are:
- Jekyll: A static site is fine, I need 0 features except a simple way to get stuff out. If there’s any difficulty publishing content I just won’t do it. I’m guessing even if there’s no difficulty I still won’t but time will tell.
- Coffeescript: Love it or hate it, it is a thing. If you’re using coffeescript to hide the fact that you don’t know javascript then I hate it. If you’re using coffeescript to write JS faster with less typing and less text then I love it.
- Sass: I feel like I’m in the middle of a sassy sandwich! There are a lot of things I dislike about my profession and CSS is one of them. Sass makes me less likely to flip my desk. (unintended less reference there)
- Grunt: I need a tool to compile the coffee and the sass. I want something to watch for my changes and compile as I change and even get super fancy and live reload my browser. I’m working in coffee already, it makes sense and I’ve wanted an excuse to use it.
Here’s my Gruntfile.coffee:
grunt.initConfig
pkg: grunt.file.readJSON('package.json'),
watch:
files: ['src/scss/*.scss', '_posts/*.md', '_layouts/*.html', '_config.yml', 'src/coffee/**/*.coffee', '*.html', 'src/coffee/templates/*.emblem']
tasks: ['default', 'shell:jekyllBuild']
options:
interrupt: true
atBegin: true
livereload: true
debounceDelay: 2000
clean: ['src/js/']
concat:
options:
separator: ';'
dist:
src: ['src/coffee/**/.js']
coffee:
compile:
files:
'js/site.js': 'src/coffee/**/*.coffee'
emblem:
compile:
files:
'js/templates.js': 'src/coffee/templates/*.emblem',
options:
root: 'src/coffee/templates/'
dependencies:
jquery: 'js/jquery.min.js'
ember: 'js/ember.min.js'
emblem: 'js/emblem.min.js'
handlebars: 'js/handlebars.min.js'
sass:
dist:
files:
'stylesheets/site.css': 'src/scss/site.scss'
'stylesheets/jellybeans.css': 'src/scss/jellybeans.scss'
'stylesheets/font-awesome.css': 'bower_components/font-awesome/scss/font-awesome.scss'
shell:
jekyllBuild:
command: 'jekyll build --drafts'
jekyllServe:
command: 'jekyll serve'
uglify:
options:
banner: '/*! <%= pkg.name %> <%= grunt.template.today("dd-mm-yyyy") %> */\n'
dist:
files:
'js/<%= pkg.name %>.min.js': ['<%= coffee,dist.dest %>']
My workflow is to open up a split terminal, both in my working directory and then run
in one and
in the other. I actually have grunt watch alias’d to gw. The great thing about grunt watch is the live reload. After everything is built my localhost:4000 auto refreshes and reflects all the changes.
Since this is getting pretty lengthy already I’ll wrap it up and save how to use this set up for your own github pages for another post.
Punchline: I still can’t think of a punchline. =\
My Dotfiles
You can find my dotfiles here. I have some aliases that I use regularly. Here’s a big one, so stupid but I feel like I do this enough to warrant it. The rest are nothing to write home about. You might argue this one is also nothing to write home about.
I use <D-F> for my fuzzy file find so I needed to remap the gui version. It’s vim, I have /, no need to hog more keys for find in file. I also decided to use <D-t> to tag search so neededt to remap new tab to <D-T>. I never knew you could just edit the gui menu so this was a nice find.
if has('gui_macvim')
macmenu Edit.Find.Find\.\.\. key=<nop>
macmenu File.New\ Tab key=<D-T>
endif
For vim / mvim I was using janus but felt it had too much stuff that I never used. I finally sat down, after almost 20 years of using vim, and created my own vim files. I used a lot of janus as a starting point since I was pretty used to it already.
Many thanks to thoughtbot for making rcm. It made the whole source controled dot files stupid simple.