Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

message widget

  • Loading branch information...
commit c986c52f6a82aa6e2a168f96ca21d678bd4b5a60 1 parent 1d31982
@phaylon authored
View
10 Todo
@@ -53,16 +53,6 @@
],
);
- · messages
-
- my $message = Message->new(
- title => 'Changes saved',
- category => 'notice',
- widgets => [
- 'Some Message',
- ],
- );
-
· dynamic containers
my $dyn = Dynamic->new(
View
2  lib/ReUI/Constants.pm
@@ -25,7 +25,7 @@ BEGIN {
[ PASSWORD_MISMATCH => 'reui.control.password.mismatch' ],
);
%SkinFile = $prepare->('SKINFILE',
- [ PAGE_HEADER_LOGO => \[qw( page header logo.png )] ],
+ [ MESSAGE_ICON_PATH => \[qw( message icon )] ],
);
%Constant = (%I18N, %SkinFile);
};
View
13 lib/ReUI/State.pm
@@ -12,6 +12,7 @@ use ReUI::Types qw(
use Carp qw( confess );
use Params::Classify qw( is_blessed is_ref is_string );
use Moose::Util qw( does_role );
+use Path::Class qw( file );
use aliased 'ReUI::Reactor';
use aliased 'ReUI::Response::Markup';
@@ -324,12 +325,24 @@ method uri_for_skin (@args) {
return $self->resolve($self->skin_uri_callback, @args);
}
+method uri_for_current_skin (@path) {
+ return undef
+ unless $self->has_current_skin;
+ $path[-1] = join('.', @{ $path[-1] })
+ if is_ref($path[-1], 'ARRAY');
+ return undef
+ unless $self->locate_skin_file($self->current_skin, file(@path));
+ return $self->uri_for_skin($self->current_skin, @path);
+}
+
has current_skin => (
is => 'rw',
isa => Str,
);
+method has_current_skin { defined $self->current_skin }
+
=method with_language
View
8 lib/ReUI/Types/Common.pm
@@ -36,6 +36,7 @@ use MooseX::Types -declare => [qw(
Renderable
StrMap
StrList
+ MessageType
)];
my $rxNamespaceStr = qr{
@@ -50,6 +51,13 @@ my $rxNamespaceStr = qr{
\Z
}x;
+enum MessageType, [qw(
+ notice
+ success
+ warning
+ error
+)];
+
subtype StrList, as ArrayRef[ Str ];
subtype StrMap, as HashRef[ Str ];
View
75 lib/ReUI/Widget/Message.pm
@@ -0,0 +1,75 @@
+use strictures 1;
+
+package ReUI::Widget::Message;
+use Moose;
+
+use ReUI::Traits qw( Resolvable );
+use ReUI::Types qw( MessageType Renderable Uri Undef );
+use ReUI::Constants qw( :skinfiles );
+use Params::Classify qw( is_blessed );
+
+use syntax qw( function method );
+use namespace::autoclean;
+
+
+has type => (
+ is => 'rw',
+ isa => MessageType,
+ required => 1,
+);
+
+has content => (
+ is => 'rw',
+ isa => Renderable,
+ required => 1,
+);
+
+
+has icon_uri => (
+ traits => [ Resolvable ],
+ is => 'ro',
+ isa => Uri | Undef,
+);
+
+
+method locate_icon_uri ($state) {
+ if (my $given = $self->resolve_icon_uri($state)) {
+ return $given;
+ }
+ return $state->uri_for_current_skin(
+ SKINFILE_MESSAGE_ICON_PATH,
+ [$self->type, 'png'],
+ );
+}
+
+method compile ($state) {
+ return $state->markup_for($self)
+ ->apply(sub {
+ my $icon_uri = $self->locate_icon_uri($state);
+ my $selected = $_->select('.message-icon');
+ defined($icon_uri)
+ ? $selected->set_attribute(src => $icon_uri)
+ : $selected->replace([]);
+ })
+ ->apply($self->identity_populator_for('.message'))
+ ->select('.message')
+ ->add_to_attribute(class => $self->type)
+ ->select('.message-content')
+ ->replace_content($state->render($self->content))
+ ->memoize;
+}
+
+method event_propagation_targets {
+ my $content = $self->content;
+ return is_blessed($content) ? $content : ();
+}
+
+
+with qw(
+ ReUI::Widget::API
+ ReUI::Widget::API::Styled
+ ReUI::Role::ElementClasses
+ ReUI::Role::EventHandling::Propagation
+);
+
+1;
View
4 share/module/ReUI-Widget-Message/base.html
@@ -0,0 +1,4 @@
+<div class="message">
+ <img class="message-icon" alt="Message icon" />
+ <div class="message-content"></div>
+</div>
View
36 t/widget-message.t
@@ -0,0 +1,36 @@
+use strictures 1;
+use Test::More;
+use Test::Fatal;
+use ReUI::Test;
+
+use aliased 'ReUI::Widget::Message';
+
+use syntax qw( function );
+
+my $msg = test_widget('message');
+
+test_processing('basic',
+ { widget => Message->new(
+ type => 'notice',
+ content => $msg,
+ id => 'test-message',
+ classes => [qw( foo bar )],
+ ),
+ prepare => {
+ current_skin => 'base',
+ },
+ },
+ test_markup(fun ($markup) {
+ $markup->into('/div', fun ($message) {
+ $message->classes(qw( message notice foo bar ));
+ $message->attr_is(id => 'test-message');
+ $message->into('./*',
+ fun ($content) {
+ $content->contains_test_value('message');
+ },
+ );
+ });
+ }),
+);
+
+done_testing;
Please sign in to comment.
Something went wrong with that request. Please try again.