Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
book-of-vaadin.pdf
Скачиваний:
88
Добавлен:
24.03.2015
Размер:
13.43 Mб
Скачать

Themes

8.3.3. Compiling On the Fly

The easiest way to use Sass themes is to let the Vaadin servlet compile them on the run. In this case, the SCSS source files are placed in the theme folder.

The on-the-fly compilation takes a bit time, so it is only available when the Vaadin servlet is in the development mode, as described in Section 4.8.4, “Other Deployment Parameters”. For production, you should compile the theme to CSS.

8.3.4. Compiling Sass to CSS

Sass style sheets can be compiled to CSS, with the styles.css of a custom theme as the compilation target. When compiled before deployment, the source files do not need to be in the theme folder.

java -cp '../../../WEB-INF/lib/*' com.vaadin.sass.SassCompiler styles.scss styles.css

The -cp parameter should point to the class path where the Vaadin JARs are located. In the above example, they are assumed to be locate in the WEB-INF/lib folder of the web application.

If you have loaded the Vaadin libraries using Ivy, as is the case with projects created with the Vaadin Plugin for Eclipse, the Vaadin libraries are stored in Ivy's local repository. Its folder hierarchy is somewhat scattered, so we recommend that you retrieve the libraries to a single folder. With Apache Ant, you can do that with an Ivy task as shown in the following example:

<project xmlns:ivy="antlib:org.apache.ivy.ant">

...

<target name="resolve" depends="init"> <ivy:retrieve

pattern="${result-dir}/lib/[module]-[type]-[artifact]-[revision].[ext]"/> </target>

</project>

8.4. Creating and Using Themes

Custom themes are placed in the VAADIN/themes folder of the web application (in an Eclipse project under the WebContent folder), as was illustrated in Figure 8.1, “Contents of a Theme”. This location is fixed.You need to have a theme folder for each theme you use in your application, although applications rarely need more than a single theme.

8.4.1. Sass Themes

You can use Sass themes in Vaadin in two ways, either by compiling them to CSS by yourself or by letting the Vaadin servlet compile them for you on-the-fly when the theme CSS is requested by the browser.

To define a Sass theme with the name mytheme, you must place a file with name styles.scss in the theme folder VAADIN/themes/mytheme. If no styles.css exists in the folder, the Sass file is compiled on-the-fly when the theme is requested by a browser.

We recommend that you organize the theme in at least two SCSS files so that you import the actual theme from a Sass file that is named more uniquely than the styles.scss, to make it more distinquishable in the editor. This is also how the Vaadin Plugin for Eclipse creates a new theme.

232

Compiling On the Fly

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]