Skip to content

Commit

Permalink
rel_2021_12_02, see Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kberov committed Dec 9, 2021
1 parent 1ff3e0b commit b96c672
Show file tree
Hide file tree
Showing 7 changed files with 179 additions and 101 deletions.
13 changes: 12 additions & 1 deletion Changes
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,18 @@ Revision history for Mojolicious application Slovo
* Fixed error in template partials/_kniga.html.ep in Slovo::Themes::Malka.
* Returned again to showing the celina used for title of a stranica in
Slovo::Controller::Celini->index().

* Added social icons from materialdesignicons.com and icon-icons.com to
Slovo::Plugin::Themes::Malka and used them in the footer. Slightly
improved CSS for mobile devices.
* Enabled partials/_right.html.ep and added <aside id="widgets"> to it to
enable plugins to put there content.
* Moved Plugins TagHelpers and DefaultHelpers to slovo.conf just after
Authentication plugin to allow their helpers to be used by plugins which
load next and still override Authentication's is_user_authenticated.
* Added two new helpers to TagHelpers plugin to allow other plugins to put
css and js files to $app->defaults so they are automatically available in
stash as <link> and <script> tags. Used the new feature in Malka.pm


2021.11.22
* Fixed wrong separator for sharer urls in _footer_right.html.ep
Expand Down
13 changes: 7 additions & 6 deletions lib/Slovo.pm
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,14 @@ sub _load_config ($app) {
my $home = $app->home;

# Load configuration from hash returned by "slovo.conf"
my $file = $etc->child("$moniker.conf");
my $mode_file = $etc->child("$moniker.$mode.conf");
my $file = $etc->child("$moniker.conf");
my $mode_file = $etc->child("$moniker.$mode.conf");
my $home_file = $home->child("$moniker.conf");
my $home_mode_file = $home->child("$moniker.$mode.conf");
$ENV{MOJO_CONFIG}
//= (-e $home->child("$moniker.$mode.conf") && $home->child("$moniker.$mode.conf"))
|| (-e $home->child("$moniker.conf") && $home->child("$moniker.conf"))
|| (-e $mode_file ? $mode_file : $file);
//= (-f $home_mode_file && $home_mode_file)
|| (-f $home_file && $home_file)
|| (-f $mode_file ? $mode_file : $file);
my $config = $app->plugin('Config');
for my $class (@{$config->{load_classes} // []}) {
Expand Down Expand Up @@ -200,7 +202,6 @@ sub _load_pugins ($app) {
# See /perldoc/Mojolicious/Plugins#PLUGINS
$app->plugins->namespaces(['Slovo::Plugin', 'Slovo', 'Mojolicious::Plugin']);
my $plugins = $app->config('load_plugins') // [];
push @$plugins, qw(DefaultHelpers TagHelpers);
foreach my $plugin (@$plugins) {
my $name = (ref $plugin ? (keys %$plugin)[0] : $plugin);

Expand Down
9 changes: 3 additions & 6 deletions lib/Slovo/Controller/Celini.pm
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ sub execute ($c, $page, $user, $l, $preview) {
lang => $celina->{language});
}

# Check for pid and page_id parameters and edirect to pages' index page if
# Check for pid and page_id parameters and redirect to pages' index page if
# needed, so the user can choose in which page to create the new writing.
my sub _validate_create ($c, $u, $l, $str) {
my $int = qr/^\d{1,10}$/;
Expand Down Expand Up @@ -257,11 +257,8 @@ sub index ($c) {
}
my $celini = $c->celini;
my $opts = {
where => {
page_id => $page_id,
%{$celini->readable_by($c->user)}
},
order_by => {-asc => [qw(page_id pid sorting id)]}};
where => {page_id => $page_id, %{$celini->readable_by($c->user)}},
order_by => {-asc => [qw(page_id pid sorting id)]}};

return $c->render(
celini => $celini->all($opts),
Expand Down
46 changes: 46 additions & 0 deletions lib/Slovo/Plugin/TagHelpers.pm
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,18 @@ sub register ($self, $app, $config) {
$app->helper(html_substr => \&_html_substr);
$app->helper(format_body => \&_format_body);

for my $h (qw(stylesheets javascripts)) {
$app->helper(
$h => sub {
state $tag = $h =~ s/s$//r;
if ($_[1]) {
my $d = $app->defaults->{$h} //= [];
push @$d, $_[0]->$tag($_[1]);
return $_[0];
}
return join $/, @{$_[0]->stash->{$h} //= []};
});
}
return $self;
}

Expand Down Expand Up @@ -158,6 +170,24 @@ are not more than C<$chars>. Starts from the first character in the first
matched C<$selector>. In case the C<$html> is simple text, produces
C<E<lt>pE<gt>> elements.
=head2 javascripts
Add one JS file to L<Mojolicious/defaults> C<<$app->defaults->{javascripts}>>.
Intended for use in a plugin's C<register> method.
$app->javascripts('/js/foo.js');
$app->javascripts('/js/bar.js');
When invoked without arguments, returns the list of generated tags for those
files, found in C<<$c->stash->{javascripts}>>.
%=javascripts
# returns
<script src="/path/to/foo.js"></script>
<script src="/path/to/bar.js"></script>
=head2 select_box
<%=
Expand All @@ -183,6 +213,22 @@ C<select_field>. If value is provided it does C<$c-E<gt>param($name =E<gt>
$attrs{value})>. The generated tags are wrapped in a C<div> tag with
C<class="mui-select $name">.
=head2 stylesheets
Adds an item to C<<$app->defaults->{stylesheets}>> and returns $c.
Intended for use in a plugin's C<register> method.
$app->stylesheets('/css/bar.css');
$app->stylesheets('/css/foo.css');
When invoked without arguments, returns the list of generated tags for those
files, found in C<<$c->stash->{stylesheets}>>.
%=stylesheets
#returns:
<link rel="stylesheet" href="/css/foo.css" />
<link rel="stylesheet" href="/css/bar.css" />
=head1 METHODS
The usual method is implemented.
Expand Down
109 changes: 78 additions & 31 deletions lib/Slovo/Themes/Malka.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,20 @@ sub register ($self, $app, $conf) {

# Prepend class
unshift @{$app->renderer->classes}, __PACKAGE__;
unshift @{$app->static->classes}, __PACKAGE__;

#Add CSS and JS to defaults for stash.
for (qw(/css/malka/chota_all_min.css
/css/fonts.css
/css/malka/site.css))
{
$app->stylesheets($_);
}
for (qw(/mojo/jquery/jquery.js)) {
$app->javascripts($_);
}

unshift @{$app->static->classes}, __PACKAGE__;

# Apppend it to the select_box in domove/_form.html.ep
# Apppend the theme to the select_box in domove/_form.html.ep
$conf //= {};
$conf->{templates} //= ['themes/malka' => 'themes/malka'];
push @{$app->config->{domove_templates} //= []}, $conf->{templates};
Expand All @@ -18,6 +28,8 @@ sub register ($self, $app, $conf) {

1;

=pod
=encoding utf8
=head1 NAME
Expand Down Expand Up @@ -107,6 +119,14 @@ using the given example at the end of the L<<DESCRIPTION>>.
@@ layouts/uprava.html.ep
@@ css/malka/chota_all_min.css
@@ css/malka/site.css
@@ css/malka/email-fast-outline.svg
@@ css/malka/facebook.svg
@@ css/malka/icons8-telegram-app.svg
@@ css/malka/linkedin.svg
@@ css/malka/reddit.svg
@@ css/malka/twitter.svg
@@ css/malka/login.svg
@@ css/malka/logout.svg
=head1 SEE ALSO
Expand Down Expand Up @@ -165,11 +185,11 @@ layout 'site',
<body>
%= include 'partials/_header'
%#= include 'partials/_left'
%#TODO:= include 'partials/_right'
<main class="container">
% my $messgage = flash('message');
%= $messgage ? t(div => (class => 'bd-error text-error') => $messgage) : ''
<%= content %>
%= include 'partials/_right'
</main>
%= include 'partials/_footer'
</body>
Expand Down Expand Up @@ -230,22 +250,22 @@ my $sharer_url = $canonical_path;
<a class="button outline primary sharer" target="_blank"
href="https://www.facebook.com/share.php?u=<%= $sharer_url %>" rel="noopener"
aria-label="Споделяне във Facebook"
title="Споделяне във Facebook">f</a><a
title="Споделяне във Facebook"><img src="/css/malka/facebook.svg"></a><a
class="button outline primary sharer" target="_blank"
href="https://www.reddit.com/submit?url=<%= $sharer_url %>"
aria-label="Споделяне в Reddit"
title="Споделяне в Reddit">r</a><a
title="Споделяне в Reddit"><img src="/css/malka/reddit.svg"></a><a
class="button outline primary sharer" target="_blank"
href="https://www.linkedin.com/shareArticle?mini=true&url=<%= $sharer_url %>&title=<%= title %>"
aria-label="Споделяне в LinkedIn"
title="Споделяне в LinkedIn">in</a><a
title="Споделяне в LinkedIn"><img src="/css/malka/linkedin.svg"></a><a
class="button outline primary sharer" target="_blank"
href="https://twitter.com/intent/tweet?url=<%= $sharer_url %>&via=@kberov&title=<%= title %>"
aria-label="Споделяне в Twitter"
title="Споделяне в Twitter">t</a><!--<a
title="Споделяне в Twitter"><img src="/css/malka/twitter.svg"></a><!--<a
class="button outline primary sharer" target="_blank"
href="https://pinterest.com/pin/create/button/?url=<%= $sharer_url %>&description=<%= title %>"
Expand All @@ -254,13 +274,13 @@ my $sharer_url = $canonical_path;
class="button outline primary sharer" target="_blank"
href="mailto:?subject=<%= title %>&body=<%= $sharer_url %>"
aria-label="Напишете писмо"
title="Напишете писмо"></a><a
aria-label="Напишете писмо на приятел"
title="Напишете писмо"><img src="/css/malka/email-fast-outline.svg"></a><a
class="button outline primary sharer" target="_blank"
href="tg://msg_url?url=<%= $sharer_url %>&text=<%= title %>"
aria-label="Споделяне в Telegram"
title="Споделяне в Telegram"></a><a
title="Споделяне в Telegram"><img src="/css/malka/icons8-telegram-app.svg"></a><a
class="button outline primary sharer" target="_blank"
aria-label="Направено съ ♥ и Слово"
Expand Down Expand Up @@ -295,10 +315,8 @@ my $sharer_url = $canonical_path;
<meta property="og:locale" content="<%= $l %>" />
<meta property="og:article:published_time" content="<%= $created_at %>" />
<meta property="og:article:modified_time" content="<%= $tstamp %>" />
<link rel="stylesheet" href="/css/malka/chota_all_min.css" />
<link rel="stylesheet" href="/css/fonts.css" />
<link rel="stylesheet" href="/css/malka/site.css" />
<script src="/mojo/jquery/jquery.js" ></script>
%== stylesheets;
%== javascripts;
</head>
@@ partials/_created_tstamp.html.ep
Expand Down Expand Up @@ -362,9 +380,9 @@ my $sharer_url = $canonical_path;
<nav class="col-2 nav-right">
% if ($c->is_user_authenticated) {
% my $name = $user->{first_name} . ' ' . $user->{last_name};
%= link_to 'Изходъ '.$name => 'sign_out'
<%= link_to sign_out => begin %><img title="<%= 'Изходъ '.$name %>" src="/css/malka/logout.svg"><% end %>
% } else {
%= link_to 'Входъ' => 'sign_in'
<%= link_to sign_in => begin%><img title="Входъ" src="/css/malka/login.svg"><% end %>
% }
%= include 'partials/_lang_menu'
</nav>
Expand Down Expand Up @@ -470,8 +488,9 @@ my $html = html_substr($celina->{teaser} // $celina->{body},
</div>
@@ partials/_right.html.ep
% if ( @$right ) {
<!-- right -->
<aside id="widgets"></aside>
% if ( @$right ) {
%= t aside => (class=>"right") => begin
<%==
$right->map(sub {
Expand Down Expand Up @@ -701,10 +720,8 @@ login_form.onsubmit = function() {
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="generator" content="Slovo <%= $Slovo::VERSION .'/'. $Slovo::CODENAME %>" />
<link rel="shortcut icon" href="/img/favicon.ico" type="image/x-icon" />
<link rel="stylesheet" href="/css/malka/chota_all_min.css" />
<link rel="stylesheet" href="/css/fonts.css" />
<link rel="stylesheet" href="/css/malka/site.css" />
<script src="/mojo/jquery/jquery.js"></script>
%== stylesheets;
%== javascripts;
</head>
<body>
<header class="is-fixed bg-dark row">
Expand Down Expand Up @@ -740,9 +757,12 @@ html{line-height:1.15;-webkit-text-size-adjust:100%}body{margin:0}main{display:b
@@ css/malka/site.css
:root {
--border-radius: 10px;
--border-radius: 10px;
--font-size: 2.2rem;
--color-success: #23FF04
--grid-maxWidth: 86rem;
}
* {
scrollbar-width: auto;
scrollbar-color: var(--color-lightGrey) var(--color-darkGrey);
Expand Down Expand Up @@ -818,10 +838,12 @@ body>header nav, body>footer nav {
margin-top: 0.5rem !important;
margin-bottom: 0.3rem !important;
}
main {
main.container {
font-size: 100%;
padding-top: 4rem !important;
padding-bottom: 4rem !important;
max-width: 86rem;
width: 80%;
}
.card {
Expand Down Expand Up @@ -854,13 +876,20 @@ footer .button.outline.primary.sharer {
color: var(--color-success);
font-weight: bolder;
border-radius: 4px;
font-size: small;
padding: .5rem 1rem;
padding: .1rem .5rem;
}
{
}
footer .button.outline.primary.sharer img {
height: .85rem;
height: 24px;
width: 24px;
display: block;
margin-left: auto;
margin-right: auto;
}
@media (max-width: 721px) {
html {
font-size: 90%;
Expand All @@ -873,15 +902,17 @@ footer .button.outline.primary.sharer img {
body>header nav,
body>footer nav {
margin: 0 !important;
font-size: 86% !important;
font-size: 70% !important;
}
.dropdown .menu a {
display: inline;
}
main {
padding-top: 5.5rem !important;
padding-bottom: 5.5rem !important;
main.container {
padding-top: 5.5rem important;
padding-bottom: 5.5rem important;
width: 90%;
}
footer .love {
display: none;
}
Expand All @@ -891,3 +922,19 @@ footer .button.outline.primary.sharer img {
}
} /* end @media (max-width: 721px) */
@@ css/malka/email-fast-outline.svg
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="24" height="24" viewBox="0 0 24 24"><path fill="white" d="M22 5.5H9C7.9 5.5 7 6.4 7 7.5V16.5C7 17.61 7.9 18.5 9 18.5H22C23.11 18.5 24 17.61 24 16.5V7.5C24 6.4 23.11 5.5 22 5.5M22 16.5H9V9.17L15.5 12.5L22 9.17V16.5M15.5 10.81L9 7.5H22L15.5 10.81M5 16.5C5 16.67 5.03 16.83 5.05 17H1C.448 17 0 16.55 0 16S.448 15 1 15H5V16.5M3 7H5.05C5.03 7.17 5 7.33 5 7.5V9H3C2.45 9 2 8.55 2 8S2.45 7 3 7M1 12C1 11.45 1.45 11 2 11H5V13H2C1.45 13 1 12.55 1 12Z" /></svg>
@@ css/malka/facebook.svg
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="24" height="24" viewBox="0 0 24 24"><path fill="white" d="M12 2.04C6.5 2.04 2 6.53 2 12.06C2 17.06 5.66 21.21 10.44 21.96V14.96H7.9V12.06H10.44V9.85C10.44 7.34 11.93 5.96 14.22 5.96C15.31 5.96 16.45 6.15 16.45 6.15V8.62H15.19C13.95 8.62 13.56 9.39 13.56 10.18V12.06H16.34L15.89 14.96H13.56V21.96A10 10 0 0 0 22 12.06C22 6.53 17.5 2.04 12 2.04Z" /></svg>
@@ css/malka/icons8-telegram-app.svg
<svg fill="white" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24px" height="24px"><path d="M 19.976562 3.1210938 L 19.611328 3.2695312 C 19.611328 3.2695312 6.6375504 8.5740484 2.6132812 10.267578 L 2.0019531 10.525391 L 2.0019531 12.779297 L 6.9472656 14.755859 L 8.6796875 19.996094 L 10.251953 20.005859 L 12.955078 17.720703 L 16.355469 20.996094 L 18.808594 20.996094 L 21.964844 3.875 L 19.976562 3.1210938 z M 19.646484 5.4179688 L 17.146484 18.980469 L 13.044922 15.029297 L 10.224609 17.410156 L 11 14.375 L 17.28125 8 L 17.082031 7.7988281 C 17.082031 7.7988281 10.706702 11.473998 8.0019531 13.023438 L 4.5371094 11.638672 C 9.0770415 9.7455758 18.697943 5.8058761 19.646484 5.4179688 z"/></svg>
@@ css/malka/linkedin.svg
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="24" height="24" viewBox="0 0 24 24"><path fill="white" d="M19 3A2 2 0 0 1 21 5V19A2 2 0 0 1 19 21H5A2 2 0 0 1 3 19V5A2 2 0 0 1 5 3H19M18.5 18.5V13.2A3.26 3.26 0 0 0 15.24 9.94C14.39 9.94 13.4 10.46 12.92 11.24V10.13H10.13V18.5H12.92V13.57C12.92 12.8 13.54 12.17 14.31 12.17A1.4 1.4 0 0 1 15.71 13.57V18.5H18.5M6.88 8.56A1.68 1.68 0 0 0 8.56 6.88C8.56 5.95 7.81 5.19 6.88 5.19A1.69 1.69 0 0 0 5.19 6.88C5.19 7.81 5.95 8.56 6.88 8.56M8.27 18.5V10.13H5.5V18.5H8.27Z" /></svg>
@@ css/malka/login.svg
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="24" height="24" viewBox="0 0 24 24"><path fill="white" d="M10,17V14H3V10H10V7L15,12L10,17M10,2H19A2,2 0 0,1 21,4V20A2,2 0 0,1 19,22H10A2,2 0 0,1 8,20V18H10V20H19V4H10V6H8V4A2,2 0 0,1 10,2Z" /></svg>
@@ css/malka/logout.svg
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="24" height="24" viewBox="0 0 24 24"><path d="M16,17V14H9V10H16V7L21,12L16,17M14,2A2,2 0 0,1 16,4V6H14V4H5V20H14V18H16V20A2,2 0 0,1 14,22H5A2,2 0 0,1 3,20V4A2,2 0 0,1 5,2H14Z" /></svg>
@@ css/malka/reddit.svg
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="24" height="24" viewBox="0 0 24 24"><path fill="white" d="M14.5 15.41C14.58 15.5 14.58 15.69 14.5 15.8C13.77 16.5 12.41 16.56 12 16.56C11.61 16.56 10.25 16.5 9.54 15.8C9.44 15.69 9.44 15.5 9.54 15.41C9.65 15.31 9.82 15.31 9.92 15.41C10.38 15.87 11.33 16 12 16C12.69 16 13.66 15.87 14.1 15.41C14.21 15.31 14.38 15.31 14.5 15.41M10.75 13.04C10.75 12.47 10.28 12 9.71 12C9.14 12 8.67 12.47 8.67 13.04C8.67 13.61 9.14 14.09 9.71 14.08C10.28 14.08 10.75 13.61 10.75 13.04M14.29 12C13.72 12 13.25 12.5 13.25 13.05S13.72 14.09 14.29 14.09C14.86 14.09 15.33 13.61 15.33 13.05C15.33 12.5 14.86 12 14.29 12M22 12C22 17.5 17.5 22 12 22S2 17.5 2 12C2 6.5 6.5 2 12 2S22 6.5 22 12M18.67 12C18.67 11.19 18 10.54 17.22 10.54C16.82 10.54 16.46 10.7 16.2 10.95C15.2 10.23 13.83 9.77 12.3 9.71L12.97 6.58L15.14 7.05C15.16 7.6 15.62 8.04 16.18 8.04C16.75 8.04 17.22 7.57 17.22 7C17.22 6.43 16.75 5.96 16.18 5.96C15.77 5.96 15.41 6.2 15.25 6.55L12.82 6.03C12.75 6 12.68 6.03 12.63 6.07C12.57 6.11 12.54 6.17 12.53 6.24L11.79 9.72C10.24 9.77 8.84 10.23 7.82 10.96C7.56 10.71 7.2 10.56 6.81 10.56C6 10.56 5.35 11.21 5.35 12C5.35 12.61 5.71 13.11 6.21 13.34C6.19 13.5 6.18 13.62 6.18 13.78C6.18 16 8.79 17.85 12 17.85C15.23 17.85 17.85 16.03 17.85 13.78C17.85 13.64 17.84 13.5 17.81 13.34C18.31 13.11 18.67 12.6 18.67 12Z" /></svg>
@@ css/malka/twitter.svg
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="24" height="24" viewBox="0 0 24 24"><path fill="white" d="M22.46,6C21.69,6.35 20.86,6.58 20,6.69C20.88,6.16 21.56,5.32 21.88,4.31C21.05,4.81 20.13,5.16 19.16,5.36C18.37,4.5 17.26,4 16,4C13.65,4 11.73,5.92 11.73,8.29C11.73,8.63 11.77,8.96 11.84,9.27C8.28,9.09 5.11,7.38 3,4.79C2.63,5.42 2.42,6.16 2.42,6.94C2.42,8.43 3.17,9.75 4.33,10.5C3.62,10.5 2.96,10.3 2.38,10C2.38,10 2.38,10 2.38,10.03C2.38,12.11 3.86,13.85 5.82,14.24C5.46,14.34 5.08,14.39 4.69,14.39C4.42,14.39 4.15,14.36 3.89,14.31C4.43,16 6,17.26 7.89,17.29C6.43,18.45 4.58,19.13 2.56,19.13C2.22,19.13 1.88,19.11 1.54,19.07C3.44,20.29 5.7,21 8.12,21C16,21 20.33,14.46 20.33,8.79C20.33,8.6 20.33,8.42 20.32,8.23C21.16,7.63 21.88,6.87 22.46,6Z" /></svg>
1 change: 1 addition & 0 deletions lib/Slovo/resources/etc/slovo.conf
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ my $mail_cfg = {
validate_user => \&Slovo::Controller::Auth::validate_user,
}
},
qw(DefaultHelpers TagHelpers),
{RoutesConfig => {file => (-e $rmf ? $rmf : $resources->child("etc/routes.conf"))}},
{
'Minion::Admin' =>
Expand Down
Loading

0 comments on commit b96c672

Please sign in to comment.