Release 0.41.92
[vala-gnome.git] / libvaladoc / content / embedded.vala
blob8eed77cfa956999c65683fab6cdfc1870c4539e7
1 /* embedded.vala
3 * Copyright (C) 2008-2009 Didier Villevalois
4 * Copyright (C) 2008-2012 Florian Brosch
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 * Author:
21 * Didier 'Ptitjes Villevalois <ptitjes@free.fr>
25 public class Valadoc.Content.Embedded : ContentElement, Inline, StyleAttributes {
26 public string url {
27 get;
28 set;
31 public string? caption {
32 get;
33 set;
36 public HorizontalAlign horizontal_align {
37 get;
38 set;
41 public VerticalAlign vertical_align {
42 get;
43 set;
46 public string? style {
47 get;
48 set;
51 public Api.Package package;
53 private ResourceLocator _locator;
55 internal Embedded () {
56 base ();
59 public override void configure (Settings settings, ResourceLocator locator) {
60 _locator = locator;
63 public override void check (Api.Tree api_root, Api.Node container, string file_path,
64 ErrorReporter reporter, Settings settings)
66 // search relative to our file
67 if (!Path.is_absolute (url)) {
68 string relative_to_file = Path.build_path (Path.DIR_SEPARATOR_S,
69 Path.get_dirname (file_path),
70 url);
71 if (FileUtils.test (relative_to_file, FileTest.EXISTS | FileTest.IS_REGULAR)) {
72 url = (owned) relative_to_file;
73 package = container.package;
74 return ;
78 // search relative to the current directory / absoulte path
79 if (!FileUtils.test (url, FileTest.EXISTS | FileTest.IS_REGULAR)) {
80 string base_name = Path.get_basename (url);
82 foreach (unowned string dir in settings.alternative_resource_dirs) {
83 string alternative_path = Path.build_path (Path.DIR_SEPARATOR_S,
84 dir,
85 base_name);
86 if (FileUtils.test (alternative_path, FileTest.EXISTS | FileTest.IS_REGULAR)) {
87 url = (owned) alternative_path;
88 package = container.package;
89 return ;
93 string node_segment = (container is Api.Package)? "" : container.get_full_name () + ": ";
94 reporter.simple_error ("%s: %s{{".printf (file_path, node_segment),
95 "'%s' does not exist", url);
96 } else {
97 package = container.package;
101 public override void accept (ContentVisitor visitor) {
102 visitor.visit_embedded (this);
105 public override bool is_empty () {
106 return false;
109 public override ContentElement copy (ContentElement? new_parent = null) {
110 Embedded embedded = new Embedded ();
111 embedded.parent = new_parent;
113 embedded.horizontal_align = horizontal_align;
114 embedded.vertical_align = vertical_align;
115 embedded._locator = _locator;
116 embedded.caption = caption;
117 embedded.package = package;
118 embedded.style = style;
119 embedded.url = url;
121 return embedded;