Branch (
branchandroot) wrote in
dreamscapes2009-08-19 12:39 pm
![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
![[site community profile]](https://www.dreamwidth.org/img/comm_staff.png)
Entry tags:
Properties and Conversion
This post is for people who want to work on converting layouts, either their own or other people's.
Layer vocabulary
Different layer types
Creating a custom layer
For those who are unfamiliar with S2, it may be easiest to learn this if you copy all of the code of the Tabula Rasa layer and paste it into a theme layer you create. Make sure the theme layer is a child of Tabula Rasa. Name it something memorable and select it as your journal theme when you want to experiment.
Tabula Rasa theme layers should look a lot like the Tabula Rasa layout layer. At the top, you will need to set the value of all the properties you use, and inside the print_stylesheet function you will need to put all your css, with properties in place of colors. Your theme stylesheet should go inside a bit of code that looks like this:
function print_stylesheet () {
"""
/* Theme CSS */
""";
}
Feel free to copy this snippet into your test theme layer and paste your CSS inside it.
Note that, while Tabula Rasa and other top level layouts use the function print_default_stylesheet, layouts that are children of Tabula Rasa will use print_stylesheet, and individual themes can use print_theme_stylesheet. This means that your theme CSS will be sitting on top of the Tabula Rasa base sheet you see in the Tabula Rasa code. Look at the base sheet to get a feel for what's already done; most of it is column positioning. If you find you need some CSS for one particular theme variation, use print_theme_stylesheet to include it.
If you've never used a function to print out a style sheet and use properties in it, you can get a feel for how it works by going to that theme layer into which you pasted the Tabula Rasa code and playing around with setting all those variables to different colors and seeing what happens. You may also want to start out by designing purely with CSS, testing that out until you're happy with it, and only then pasting your CSS into your test theme layer and replacing the color codes with properties.
set color_page_background = "#ffffff";
If you leave the quotation marks empty, as Tabula Rasa does, then the property has no setting. If you aren't using a property in your theme, you might as well delete it, it will make keeping track of things easier.
body { background: #006633 url("path/to/your/image.jpg") repeat-x; }
.entry { background-color: #ffffff; border: 1px solid #999999; }
.entry-title { background-color: #006633; }
When you take that css and put it inside the print_stylesheet function, it should look like this:
body { background: $*color_page_background url("$*image_background_page_url") $*image_background_page_repeat; }
.entry { background-color: $*color_entry_background; border: 1px solid $*color_entry_border; }
.entry-title { background-color: $*color_entry_header_background; }
And all those properties will need to be set, at the top of your theme, using the colors and image path from the original css.
Note that, although the body background and header background are the same color, they use different properties, which will both have to be set with that hex color. Why go to all this trouble? So that users will be able to customize your theme easily! So that, if they want to use a different background image, if they want to change the entry colors to light text on a dark background, they will be able to do so. Always try to use the appropriate property for the page element you're setting colors for.
In many cases, however, all you will really need to do is set the color values. The base sheet will do a great many things for you.
There are a handful of small pre-written functions in Core and Tabula Rasa that spit out text color, background color and background image css when called on. If you look at the Tabula Rasa code, right at the top of the print_default_stylesheet function there's a long list of things that start with "var". Those set the pre-written code spitting functions. If you look a little further down you can see that, for example, the body css contains a line that only reads "$page_background". That calls on the pre-written function above to put several properties together and spit out the right css. So you can just set the properties at the top of your theme and the little functions will output the background-making css for you.
Be aware, these can also interfere with your css! If you have added your CSS to your theme and set the properties, and find that your backgrounds aren't working the way you expect them to, or you have unexpected borders, look up through the base style sheet code or the html output and see if the base sheet is printing something that conflicts with your CSS. You may need to re-phrase your CSS rules to override the base sheet in places.
If you wish to design without using the base sheet, you can do this by using print_default_stylesheet to enclose your CSS, rather than using print_stylesheet. Be aware that, if you do this, you will need to write all of the different column-left, column-right placement that the base sheet contains into your theme sheet.
Basic Terms
If you are not familiar with S2 coding or the making and use of layers, please read these faqs first. Parts of them will not quite fit. The links go to LJ documentation because our Documentation Team is still in the process of documenting the S2 system here (and they are doing a fantastic job and everyone should thank them).Layer vocabulary
Different layer types
Creating a custom layer
For those who are unfamiliar with S2, it may be easiest to learn this if you copy all of the code of the Tabula Rasa layer and paste it into a theme layer you create. Make sure the theme layer is a child of Tabula Rasa. Name it something memorable and select it as your journal theme when you want to experiment.
Introducing properties
If you've taken a look at the code of Tabula Rasa, you've probably noticed it's pretty much a bunch of properties and a style sheet. Some of those properties are marked as "Page colors", "Entry colors", etc and look like color_entry_text or color_module_link. They are one of the big changes in Dreamwidth's version 2 of the Core layer. All of those color and background properties can be adjusted by any user through the Customize Style wizard, so we want to use them in all theme style sheets to make the themes as flexible and customizable as possible.Tabula Rasa theme layers should look a lot like the Tabula Rasa layout layer. At the top, you will need to set the value of all the properties you use, and inside the print_stylesheet function you will need to put all your css, with properties in place of colors. Your theme stylesheet should go inside a bit of code that looks like this:
function print_stylesheet () {
"""
/* Theme CSS */
""";
}
Feel free to copy this snippet into your test theme layer and paste your CSS inside it.
Note that, while Tabula Rasa and other top level layouts use the function print_default_stylesheet, layouts that are children of Tabula Rasa will use print_stylesheet, and individual themes can use print_theme_stylesheet. This means that your theme CSS will be sitting on top of the Tabula Rasa base sheet you see in the Tabula Rasa code. Look at the base sheet to get a feel for what's already done; most of it is column positioning. If you find you need some CSS for one particular theme variation, use print_theme_stylesheet to include it.
If you've never used a function to print out a style sheet and use properties in it, you can get a feel for how it works by going to that theme layer into which you pasted the Tabula Rasa code and playing around with setting all those variables to different colors and seeing what happens. You may also want to start out by designing purely with CSS, testing that out until you're happy with it, and only then pasting your CSS into your test theme layer and replacing the color codes with properties.
How to set a property
This is very simple. At the top of your theme you need to set a value for each property you use. It will look like this:set color_page_background = "#ffffff";
If you leave the quotation marks empty, as Tabula Rasa does, then the property has no setting. If you aren't using a property in your theme, you might as well delete it, it will make keeping track of things easier.
How to use a property
So, let's say that you have designed a theme in which the page background is an image over a color, the entry background is white with a gray border, and the entry header is the same as the background color. Your original css might look like this:body { background: #006633 url("path/to/your/image.jpg") repeat-x; }
.entry { background-color: #ffffff; border: 1px solid #999999; }
.entry-title { background-color: #006633; }
When you take that css and put it inside the print_stylesheet function, it should look like this:
body { background: $*color_page_background url("$*image_background_page_url") $*image_background_page_repeat; }
.entry { background-color: $*color_entry_background; border: 1px solid $*color_entry_border; }
.entry-title { background-color: $*color_entry_header_background; }
And all those properties will need to be set, at the top of your theme, using the colors and image path from the original css.
Note that, although the body background and header background are the same color, they use different properties, which will both have to be set with that hex color. Why go to all this trouble? So that users will be able to customize your theme easily! So that, if they want to use a different background image, if they want to change the entry colors to light text on a dark background, they will be able to do so. Always try to use the appropriate property for the page element you're setting colors for.
In many cases, however, all you will really need to do is set the color values. The base sheet will do a great many things for you.
The refinements
That body background css above? In actuality, you won't need to write out that css if you don't want to, because the Styles Team has done it for you already.There are a handful of small pre-written functions in Core and Tabula Rasa that spit out text color, background color and background image css when called on. If you look at the Tabula Rasa code, right at the top of the print_default_stylesheet function there's a long list of things that start with "var". Those set the pre-written code spitting functions. If you look a little further down you can see that, for example, the body css contains a line that only reads "$page_background". That calls on the pre-written function above to put several properties together and spit out the right css. So you can just set the properties at the top of your theme and the little functions will output the background-making css for you.
Be aware, these can also interfere with your css! If you have added your CSS to your theme and set the properties, and find that your backgrounds aren't working the way you expect them to, or you have unexpected borders, look up through the base style sheet code or the html output and see if the base sheet is printing something that conflicts with your CSS. You may need to re-phrase your CSS rules to override the base sheet in places.
If you wish to design without using the base sheet, you can do this by using print_default_stylesheet to enclose your CSS, rather than using print_stylesheet. Be aware that, if you do this, you will need to write all of the different column-left, column-right placement that the base sheet contains into your theme sheet.
no subject
no subject
no subject
The only thing I wanted to know that you didn't explain was how to escape quotes. Does the same escaping apply in S2, v2?
(People who are setting fonts with spaces in the name, e.g. Times New Roman, should put quotation marks around the name to make them display properly. I get funny results in Ubuntu sometimes when people don't.)
(no subject)
no subject
Also, it occurs to me that you didn't explain why some of the variables in your CSS example above had asterisks in them.
(no subject)
(no subject)
(no subject)
(no subject)
(no subject)
(no subject)
(no subject)
(no subject)
(no subject)
print_default_stylesheet
If you want to take what was essentially a theme for Tabula Rasa and write it as a layout, so one can use print_default_stylesheet, are there any functions that need to be re-written in the layout layer in addition to setting properties and writing the css?
Re: print_default_stylesheet
Re: print_default_stylesheet
no subject
(no subject)
(no subject)
(no subject)
(no subject)
(no subject)
(no subject)
(no subject)
(no subject)
(no subject)
(no subject)
(no subject)
(no subject)
(no subject)
(no subject)
(no subject)
Two-column option
Re: Two-column option
Re: Two-column option
Re: Two-column option
Re: Two-column option
Re: Two-column option
Re: Two-column option
(no subject)
(no subject)
(no subject)
(no subject)
(no subject)
(no subject)
no subject
(no subject)
no subject
(no subject)
no subject
Presuming that's correct, then this means the logic is that you have property, set value, create tossed-salad of globals using values as set in this instance and output local variables. Thus if you reset a property (as for a child theme), this tossed-salad step rejuggles the property values into a new local variable. Yes? No?
Hm. What is the reasoning (if any) behind not just taking the global straight up, that is, instead of:
var string page_background = generate_background_css ... etc etc
which shows up again as:
body { $page_background ... etc etc
why not skip the combination step and just do:
body { background: $*color_page_whatever url($*url_page_whatever) ... etc etc
Or is the combine-global-with-this-value a required step to be able to do children styles?
(Babe, soon as you saw my name on here you probably knew what was coming, eh. I can't make heads nor tails of any language until I can grasp the grammar. Aka, "but why can't I say ain't?" !)
(no subject)
(no subject)
(no subject)