Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'special' attribute to Mojolicious::Static #1113

Merged
merged 1 commit into from Jul 26, 2017

Conversation

lindleyw
Copy link
Contributor

@lindleyw lindleyw commented Jul 25, 2017

…to permit examining, overriding, or disabling any or all bundled files. May resolve #1094

Summary

Enumerate bundled, static files so application can examine or modify their resolution at runtime. For example, a Mojolicious::Lite app could:

delete app->static->special->{'favicon.ico'};

and then proceed to serve favicon.ico from a route.

app->static->special->{'mojo/jquery/jquery.js'} =
  app->home->child('resources', 'jquery.js');

would override the built-in jQuery for error pages with one in the app's resources directory.

Note: It might also be desirable to permit values which are Mojo::Asset objects, rather than filenames.

References

issue #1094

@kraih
Copy link
Member

kraih commented Jul 25, 2017

I like this solution. But i think the attribute should have a more generic name, since anyone can add more "special" files (which is fine). And of course the implementation needs to be cleaner, and tests/documentation added.

@lindleyw lindleyw force-pushed the enumerated-bundled branch 2 times, most recently from 2305883 to c08c65c Compare July 26, 2017 00:14
@lindleyw lindleyw changed the title Add 'bundled' attribute to Mojolicious::Static Add 'special' attribute to Mojolicious::Static Jul 26, 2017
app->home->child('resources', 'jquery.js');

would override the built-in jQuery for error pages with one in the app's
C<resources> directory.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not the correct documentation format for attributes. Please replicate the style of the surrounding documentation.

return $self->_get_file(path($PUBLIC, split('/', $rel))->to_string);
# Search special files
return undef unless exists $self->special->{$rel};
return $self->_get_file($self->special->{$rel});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The attribute accessor is called twice.

my $special = $self->special;
return exists $special->{$rel} ? $self->_get_file($special->{$rel}) : undef;

)
}
};
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I doubt the $_->to_rel($public)->to_string works on Windows.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed by AppVeyor test results.

…verriding, or disabling any or all bundled files. Resolves mojolicious#1094

change 'bundled' to 'special'; add document
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MyApp in production serves a jQuery and other debug-only resources
2 participants