Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions lib/stylus/runtime/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ function compile(str, options, plugins, imports, definitions) {
obj = definitions[definition];
value = obj.value

if(obj.literal) {
value = new stylus.nodes.Literal(value);
if (typeof value == 'object') {
style.define(definition, value, true);
} else {
if(obj.literal == true) {
value = new stylus.nodes.Literal(value);
}
style.define(definition, value);
}

style.define(definition, value);
}

style.render(function(error, css) {
Expand All @@ -37,4 +40,4 @@ function convert(str) {

function version() {
return stylus.version;
}
}
8 changes: 8 additions & 0 deletions spec/stylesheets/definition_hash.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

p
text-align my_obj['text_align']

if my_obj.if_cond
indent = my_obj['text_indent']
div
text-indent unquote(indent)
30 changes: 30 additions & 0 deletions spec/stylus_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,36 @@
expect(Stylus.compile(input)).to match(/content: red/)
end

it 'defines a hash variable' do
obj = {
:text_indent => '10px',
:text_align => 10,
:if_cond => true,
}
Stylus.define :my_obj, obj

input, _output = fixture(:definition_hash)

compiled = Stylus.compile(input)
expect(compiled).to match(/text-indent: 10px/)
expect(compiled).to match(/text-align: 10\b/)
end

it 'defines a hash variable and supports if' do
obj = {
:text_indent => '20px',
:text_align => 20,
:if_cond => false,
}
Stylus.define :my_obj, obj

input, _output = fixture(:definition_hash)

compiled = Stylus.compile(input)
expect(compiled).to_not match(/text-indent: 20px\b/)
expect(compiled).to match(/text-align: 20\b/)
end

it 'includes and imports "nib" automatically' do
Stylus.nib = true
input, output = fixture(:nib)
Expand Down