एक विशेषता के लिए, आप =
के बाद गहरे लाल रंग का कोड लिख सकते हैं, लेकिन अगर माणिक कोड उस में रिक्त स्थान है, तो आप गहरे लाल रंग का कोड के आसपास कोष्ठक डाल करने के लिए है:
option[value="1" selected=("selected" if @title=="Mrs.")] "Mrs."
देखें "रूबी जिम्मेदार बताते हैं" यहाँ : http://rdoc.info/gems/slim/frames।
कोष्ठक वैकल्पिक हैं, तो आप भी इस तरह यह लिख सकते हैं:
option value="1" selected=("selected" if @title=="Mrs.") "Mrs."
या, कोष्ठक के बजाय, आप एक अलग सीमांकक का उपयोग कर सकते हैं:
option {value="1" selected=("selected" if @title=="Mrs.")} "Mrs."
यहाँ यह कुछ के साथ है कोड:
slim.slim:
doctype html
html
head
title Slim Examples
meta name="keywords" content="template language"
body
h1 Markup examples
p This example shows you how a basic Slim file looks like.
select
option[value="1" selected=("selected" if @title=="Mr.")] "Mr."
option[value="2" selected=("selected" if @title=="Mrs.")] "Mrs."
रेल के बिना एक स्टैंडअलोन माणिक कार्यक्रम में स्लिम का उपयोग करना:
require 'slim'
template = Slim::Template.new(
"slim.slim",
pretty: true #pretty print the html
)
class Person
attr_accessor :title
def initialize title
@title = title
end
end
person = Person.new("Mrs.")
puts template.render(person)
--output:--
<!DOCTYPE html>
<html>
<head>
<title>
Slim Examples
</title>
<meta content="template language" name="keywords" />
</head>
<body>
<h1>
Markup examples
</h1>
<p>
This example shows you how a basic Slim file looks like.
</p>
<select><option value="1">"Mr."</option><option selected="selected" value="2">"Mrs."</option></select>
</body>
</html>
मैं स्ट्रिंग "गलत" के रूप में व्याख्या की है सच लगता है।
हां। झूठ का मूल्यांकन करने वाली एकमात्र चीजें झूठी खुद और शून्य हैं। कोई भी संख्या (0 सहित), कोई स्ट्रिंग ("" सहित), और किसी भी सरणी ([] सहित), आदि सभी सत्य हैं।
आपकी समस्या से संबंधित नहीं है, लेकिन शायद भविष्य के खोजकर्ता के लिए उपयोगी है ... मुझे लगता है कि स्लिम प्रस्तुत करने के लिए तर्क के रूप में आप जो भी ऑब्जेक्ट पास करते हैं, उसमें आवृत्ति चर दिखता है। इसलिए यदि आप टेम्पलेट के लिए मूल्यों का पूरा समूह प्रदान करना चाहते हैं, तो आप लिख सकते हैं:
require 'slim'
template = Slim::Template.new(
"slim.slim",
pretty: true #pretty print the html
)
class MyVals
attr_accessor :count, :title, :animals
def initialize count, title, animals
@count = count
@title = title
@animals = animals
end
end
vals = MyVals.new(4, "Sir James III", %w[ squirrel, monkey, cobra ])
puts template.render(vals)
पतला।स्लिम:
doctype html
html
head
title Slim Examples
meta name="keywords" content="template language"
body
p [email protected]
p [email protected]
p [email protected][-1]
न तो ओपनस्ट्रक्चर और न ही निर्माण के साथ काम का निर्माण() हालांकि वे प्राकृतिक उम्मीदवारों की तरह लगते हैं।