PageRenderTime 49ms CodeModel.GetById 22ms app.highlight 24ms RepoModel.GetById 1ms app.codeStats 0ms

/src/install/z_install_defaultdata.erl

http://github.com/zotonic/zotonic
Erlang | 186 lines | 131 code | 27 blank | 28 comment | 2 complexity | 72a62c9f963f5cf889a0a281d3dd27be MD5 | raw file
  1%% @author Arjan Scherpenisse <arjan@scherpenisse.net>
  2%% @copyright 2011 Arjan Scherpenisse
  3%%
  4%% @doc Installs default data in a Zotonic site.
  5
  6%% Copyright 2011 Arjan Scherpenisse
  7%%
  8%% Licensed under the Apache License, Version 2.0 (the "License");
  9%% you may not use this file except in compliance with the License.
 10%% You may obtain a copy of the License at
 11%% 
 12%%     http://www.apache.org/licenses/LICENSE-2.0
 13%% 
 14%% Unless required by applicable law or agreed to in writing, software
 15%% distributed under the License is distributed on an "AS IS" BASIS,
 16%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 17%% See the License for the specific language governing permissions and
 18%% limitations under the License.
 19
 20-module(z_install_defaultdata).
 21-author("Arjan Scherpenisse <arjan@scherpenisse.net>").
 22
 23-include("zotonic.hrl").
 24
 25%% interface functions
 26-export([
 27    install/2,
 28    default_menu/1
 29]).
 30
 31
 32install(basesite, Context) ->
 33    Datamodel = #datamodel{
 34         resources =
 35             [
 36              {page_home,
 37               text,
 38               [{title, <<"Home">>},
 39                {summary, <<"Welcome to your new site!">>},
 40                {page_path, <<"/">>}]
 41              }
 42             ]
 43        },
 44    ?DEBUG("Installing basesite data"),
 45    z_datamodel:manage(?MODULE, Datamodel, Context);
 46
 47install(blog, Context) ->
 48    Now = {{2012,12,14},{9,12,0}},
 49    Datamodel = 
 50        #datamodel{
 51      resources =
 52      [
 53       
 54       %% MENU ENTRIES
 55       
 56       {page_home,
 57        text,
 58        [{title, <<"Home">>},
 59         {summary, <<"Welcome to your blog!">>},
 60         {page_path, <<"/">>}]
 61       },
 62
 63       {page_about,
 64        text,
 65        [{title, <<"About this blog">>},
 66         {summary, <<"This is your blog!! It would be wise to type some text here on what you will be writing about. Of course, this page is just a demo page and can be deleted just as well.">>}]
 67       },
 68
 69       {page_contact,
 70        text,
 71        [{title, <<"Contact">>},
 72         {summary, <<"Get in contact with us! Use the form below to send this site's administrator some feedback on how you perceive this site.">>},
 73         {page_path, <<"/contact">>}]
 74       },
 75
 76       %% BLOG ENTRIES
 77
 78       {blog_article_welcome,
 79        article,
 80        [{title, <<"Welcome to Zotonic!">>},
 81         {publication_start, Now},
 82         {summary, <<"Zotonic is the content management system for people that want a fast, extensible, flexible and complete system for dynamic web sites. It is built from the ground up with rich internet applications and web publishing in mind.">>},
 83         {body, {file, datafile(blog, "welcome.html")}}
 84        ]
 85       },
 86       {blog_article_learnmore,
 87        article,
 88        [{title, <<"Want to learn more?">>},
 89         {publication_start, z_datetime:prev_day(Now)},
 90         {summary, <<"This blog website you're looking demonstrates only a small part of what you can do with a Zotonic site. For instance, did you know that sending mass-mailings is a builtin module? That it does OAuth out of the box? That Zotonic sites are SEO optimized by default?">>},
 91         {body, {file, datafile(blog, "learnmore.html")}}
 92        ]
 93       },
 94       {blog_article_demo,
 95        article,
 96        [{title, <<"Zotonic's Typography">>},
 97         {publication_start, z_datetime:prev_month(Now)},
 98         {summary, <<"This article demonstrates the typographic features that Zotonic has. It shows creating ordered and unordered lists, blockquotes, and different methods of embedding media, even even showing an embedded video from Vimeo.com.">>},
 99         {body, {file, datafile(blog, "demo.html")}}
100        ]
101       },
102
103       %% KEYWORDS
104
105       {kw_announcement,
106        keyword,
107        [{title, <<"Announcement">>}]
108       },
109       {kw_technical,
110        keyword,
111        [{title, <<"Technical">>}]
112       },
113       {kw_support,
114        keyword,
115        [{title, <<"Support">>}]
116       }
117      ],
118
119      media =
120      [
121       {media_learning,
122        datafile(blog, "learning.jpg"),
123        [{title, <<"A bunch of computer books">>},
124         {summary, <<"Taken by Sibi from Flickr, licensed Attribution-Noncommercial-No Derivative Works 2.0.">>}]
125       },
126       {media_welcome,
127        datafile(blog, "welcome.jpg"),
128        [{title, <<"Rocky sunrise">>},
129         {summary, <<"Taken by Grant MacDonald from Flickr, CC licensed Attribution-Noncommercial 2.0.">>}]
130       },
131       {media_video,
132        [{title, <<"Zotonic introduction video">>},
133         {oembed_url, <<"http://vimeo.com/7630916">>}]
134       }
135      ],
136
137      edges = 
138      [
139       {blog_article_learnmore, author, administrator},
140       {blog_article_welcome, author, administrator},
141       {blog_article_demo, author, administrator},
142       
143       {blog_article_learnmore, subject, kw_support},
144       {blog_article_demo, subject, kw_technical},
145       {blog_article_welcome, subject, kw_support},
146       {blog_article_welcome, subject, kw_announcement},
147       
148       {blog_article_welcome, depiction, media_welcome},
149       {blog_article_learnmore, depiction, media_learning},
150       {blog_article_demo, depiction, media_welcome}
151       
152      ]
153     },
154
155    ?DEBUG("Installing blog data"),
156    z_datamodel:manage(?MODULE, Datamodel, Context);
157
158
159install(_, _) ->
160    %% no/unknown skeleton = no default data
161    ok.
162
163
164%% @doc Retrieve the default menu structure for a given site. Used by mod_menu to create the menu.
165%% The menu can be defined in the site config file as a list of menu items under the key <tt>install_menu</tt>.
166%% If that is not defined, a default menu for the skeleton is used, if any.
167-spec default_menu(#context{}) -> MenuItems | undefined when
168      MenuItems :: [MenuItem],
169      MenuItem :: {PageName, MenuItems},
170      PageName :: atom().
171default_menu(Context) ->
172    case m_site:get(install_menu, Context) of
173        Menu when is_list(Menu) -> Menu;
174        _ -> default_skeleton_menu(m_site:get(skeleton, Context))
175    end.
176
177default_skeleton_menu(blog) ->
178    [{page_home, []}, {page_about, []}, {page_contact, []}];
179default_skeleton_menu(_) ->
180    %% no/unknown skeleton = no default menu
181    undefined.
182
183%% @doc Helper function for getting an absolute path to a data file
184%%      that is part of the default data for a site skeleton.
185datafile(Skeleton, Filename) ->
186    filename:join([z_utils:lib_dir(priv), "install", Skeleton, Filename]).