Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial version.

  • Loading branch information...
commit d6c31360909bab9cbe427017d2cac482ba03ec48 0 parents
@usualoma authored
155 Build.PL
@@ -0,0 +1,155 @@
+use strict;
+use warnings;
+use Module::Build;
+use File::Spec;
+use File::Basename;
+use YAML qw/ LoadFile /;
+
+my $class = Module::Build->subclass(
+ class => 'MTToiplanPluginDirectoryBuilder',
+ code => q{
+ # Don't make blib
+ # sub ACTION_code {};
+ # Don't make blib
+ sub ACTION_docs {};
+ # Don't make META.yml
+ sub ACTION_distmeta {
+ # no warning on ACTION_distdir
+ $_[0]->{metafile} = 'MANIFEST';
+ };
+ # Don't add MEATA.yml to MANIFEST
+ sub ACTION_manifest {
+ $_[0]->{metafile} = 'MANIFEST',
+ $_[0]->SUPER::ACTION_manifest(@_);
+ };
+ sub ACTION_test {
+ my $p = $_[0]->{properties};
+ unshift(
+ @INC,
+ File::Spec->catdir($p->{base_dir}, 'extlib'),
+ File::Spec->catdir($p->{base_dir}, '../../lib'),
+ File::Spec->catdir($p->{base_dir}, '../../extlib'),
+ );
+
+ $_[0]->SUPER::ACTION_test(@_);
+ };
+
+ sub ACTION_google_upload {
+ my ($self) = @_;
+ my @info = `git svn info 2>/dev/null`;
+ if (! @info) {
+ @info = `svn info 2>/dev/null`;
+ }
+ if (! @info) {
+ die;
+ }
+ my $prj = join('', grep($_ =~ m/^Repository Root/, @info));
+ $prj =~ s{.*//|\.googlecode\.com.*}{}gi;
+
+ my $ver = $self->dist_version;
+ my $dist_dir = $self->dist_dir;
+ my $name = $self->dist_name;
+
+ $self->depends_on('dist');
+ #$self->_call_action('distdir');
+ $self->ACTION_distdir;
+ $self->depends_on('zipdist');
+ system(
+ "googlecode_upload.py -s 'Release $ver (TGZ)' -p $prj -l $name $dist_dir.tar.gz"
+ );
+ system(
+ "googlecode_upload.py -s 'Release $ver (ZIP)' -p $prj -l $name $dist_dir.zip"
+ );
+ unlink("$dist_dir.tar.gz");
+ unlink("$dist_dir.zip");
+ };
+
+ sub ACTION_github_upload {
+ my ($self) = @_;
+ my $repos = `git config --get remote.origin.url`;
+ $repos =~ s/^.*:|\.git[\r\n]*$//g;
+ my $token = `git config --get github.token`;
+ $token =~ s/\r|\n//g;
+ my $user = `git config --get github.user`;
+ $user =~ s/\r|\n//g;
+
+ my $ver = $self->dist_version;
+ my $dist_dir = $self->dist_dir;
+ my $name = $self->dist_name;
+
+ $self->depends_on('dist');
+ #$self->_call_action('distdir');
+ $self->ACTION_distdir;
+ $self->depends_on('zipdist');
+
+ require Net::GitHub::Upload;
+ my $github = Net::GitHub::Upload->new(
+ login => $user,
+ token => $token,
+ );
+
+ # upload a file
+ $github->upload(
+ repos => $repos,
+ name => undef,
+ description => "Release $ver (TGZ)",
+ file => "$dist_dir.tar.gz",
+ );
+
+ $github->upload(
+ repos => $repos,
+ name => undef,
+ description => "Release $ver (ZIP)",
+ file => "$dist_dir.zip",
+ );
+
+ unlink("$dist_dir.tar.gz");
+ unlink("$dist_dir.zip");
+ };
+
+ sub ACTION_zipdist {
+ my ($self) = @_;
+ my $dist_dir = $self->dist_dir;
+ $self->depends_on('distdir');
+ print "Creating $dist_dir.zip\n";
+ system("zip -r $dist_dir.zip $dist_dir") == 0 or die $?;
+ $self->delete_filetree($dist_dir);
+ }
+
+ sub ACTION_distdir {
+ my ($self) = @_;
+
+ $_[0]->SUPER::ACTION_distdir(@_);
+
+ my $dist_dir = $self->dist_dir;
+ rename($dist_dir, $self->{properties}{dist_name});
+ use File::Path;
+ use File::Spec;
+ use File::Basename;
+ my $plugins = File::Spec->catfile($dist_dir, 'plugins');
+ mkpath($plugins, 1, 0755);
+
+ my $new_dist_dir = File::Spec->catfile(
+ $plugins, $self->{properties}{dist_name}
+ );
+ rename($self->{properties}{dist_name}, $new_dist_dir);
+
+ foreach my $f (glob(File::Spec->catfile($new_dist_dir, 'LIC*'))) {
+ rename($f, File::Spec->catfile($dist_dir, basename($f)));
+ }
+ }
+ }
+);
+
+my $yaml = LoadFile(File::Spec->catfile(dirname(__FILE__), 'config.yaml'));
+
+my $builder = $class->new(
+ dist_name => $yaml->{name},
+ dist_author => 'Taku Amano <taku@toi-planning.net>',
+ dist_version => $yaml->{version},
+ module_name => $yaml->{name} . '::App',
+ license => 'MIT License',
+ add_to_cleanup => [ $yaml->{name} . '-*' ],
+);
+
+$builder->create_build_script();
21 LICENSE
@@ -0,0 +1,21 @@
+enhancedinclude-mtplugin
+
+Copyright (c) 2011 ToI Inc. All rights reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
7 MANIFEST
@@ -0,0 +1,7 @@
+config.yaml
+lib/EnhancedInclude.pm
+lib/EnhancedInclude/L10N.pm
+lib/EnhancedInclude/L10N/en_us.pm
+lib/EnhancedInclude/L10N/ja.pm
+LICENSE
+README.md
49 MANIFEST.SKIP
@@ -0,0 +1,49 @@
+^MANIFEST
+\bBuild.PL$
+#^Makefile
+#^META.yml$
+#^blib/
+#~$
+
+
+# Avoid version control files.
+\bRCS\b
+\bCVS\b
+,v$
+\B\.svn\b
+\B\.git\b
+\B\.cvsignore$
+
+# Avoid Makemaker generated and utility files.
+\bMakefile$
+\bblib
+\bMakeMaker-\d
+\bpm_to_blib$
+\bblibdirs$
+^MANIFEST\.SKIP$
+
+# Avoid Module::Build generated and utility files.
+\bBuild$
+\bBuild.bat$
+\b_build
+
+# Avoid Devel::Cover generated files
+\bcover_db
+
+# Avoid temp and backup files.
+~$
+\.tmp$
+\.old$
+\.bak$
+\#$
+\.#
+\.rej$
+
+# Avoid OS-specific files/dirs
+# Mac OSX metadata
+\B\.DS_Store
+# Mac OSX SMB mount metadata files
+\B\._
+# Avoid archives of this distribution
+\bEnhancedInclude-[\d\.\_]+
+^MYMETA.yml$
37 README.md
@@ -0,0 +1,37 @@
+# DESCRIPTION
+
+A Plugin that add some modifiers to mt:Include.
+
+## FEATURES/PROBLEMS
+
+* Include, and cache execution result of command.
+* Include, and cache other site's resource.
+
+## SYNOPSIS
+### execute
+ <mt:Include execute="php" params="$filename","$arg1","$arg2" ttl="3600" />
+### url
+ <mt:Include url="http://localhost/some/part.php" ttl="3600" />
+
+## LICENSE
+
+Copyright (c) 2011 Taku AMANO
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
18 config.yaml
@@ -0,0 +1,18 @@
+#plugin information
+id: EnhancedInclude
+name: EnhancedInclude
+version: 0.1.0
+
+#about this plugin
+description: <__trans phrase="Extends mt:Include">
+author_name: <__trans phrase="toi-planning">
+author_link: http://tec.toi-planning.net/
+plugin_link: http://tec.toi-planning.net/mt/enhancedinclude/
+doc_link: http://tec.toi-planning.net/mt/enhancedinclude/manual
+
+#Localization
+l10n_class: EnhancedInclude::L10N
+
+tags:
+ function:
+ Include: $EnhancedInclude::EnhancedInclude::_hdlr_include
117 lib/EnhancedInclude.pm
@@ -0,0 +1,117 @@
+# Copyright (c) 2011 ToI Inc. All rights reserved.
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+#
+# $Id$
+
+package EnhancedInclude;
+
+use Digest::MD5 qw( md5_hex );
+
+use strict;
+use warnings;
+
+sub _hdlr_include {
+ my ($ctx, $arg, $cond) = @_;
+
+ if ($arg->{execute}) {
+ return _hdlr_include_execute(@_);
+ }
+ elsif ($arg->{url}) {
+ return _hdlr_include_url(@_);
+ }
+ else {
+ defined(my $result = $ctx->super_handler($arg, $cond))
+ or return $ctx->error($ctx->errstr);
+ return $result;
+ }
+}
+
+sub _hdlr_include_execute {
+ my ($ctx, $arg, $cond) = @_;
+ my $exec = $arg->{execute};
+ my $cache_key = md5_hex('include_execute::' . $exec);
+ my $params = $arg->{params} || [];
+ if (! ref $params) {
+ $params = [ $params ];
+ }
+
+ if (my $cached = &_get_cache($cache_key, @_)) {
+ return $cached;
+ }
+
+ my $value = do{ open(my $fh, '-|', $exec, @$params); local $/; <$fh> };
+
+ &_set_cache($cache_key, $value, @_);
+}
+
+sub _hdlr_include_url {
+ my ($ctx, $arg, $cond) = @_;
+ my $url = $arg->{url};
+ my $cache_key = md5_hex('include_url::' . $url);
+
+ if (my $cached = &_get_cache($cache_key, @_)) {
+ return $cached;
+ }
+
+ my $ua = MT->new_ua;
+ my $response = $ua->get($url);
+
+ my $value = '';
+ if ($response->is_success) {
+ $value =
+ $response->can('decoded_content')
+ ? $response->decoded_content
+ : $response->content;
+ }
+ else {
+ return $ctx->error($response->status_line);
+ }
+
+ &_set_cache($cache_key, $value, @_);
+}
+
+sub _get_cache {
+ my ($cache_key, $ctx, $arg, $cond) = @_;
+
+ my $ttl = $arg->{ttl}
+ or return '';
+
+ require MT::Cache::Negotiate;
+ my $cache_driver = MT::Cache::Negotiate->new( ttl => $ttl );
+ $cache_driver->get($cache_key);
+}
+
+sub _set_cache {
+ my ($cache_key, $value, $ctx, $arg, $cond) = @_;
+
+ if (MT->version_number >= 5.0) {
+ Encode::_utf8_on($value);
+ }
+
+ my $ttl = $arg->{ttl}
+ or return $value;
+ require MT::Cache::Negotiate;
+ my $cache_driver = MT::Cache::Negotiate->new( ttl => $ttl );
+ $cache_driver->replace($cache_key, $value, $ttl);
+
+ $value;
+}
+
+1;
5 lib/EnhancedInclude/L10N.pm
@@ -0,0 +1,5 @@
+package EnhancedInclude::L10N;
+use strict;
+use base 'MT::Plugin::L10N';
+
+1;
9 lib/EnhancedInclude/L10N/en_us.pm
@@ -0,0 +1,9 @@
+package EnhancedInclude::L10N::en_us;
+
+use strict;
+
+use base 'EnhancedInclude::L10N';
+use vars qw( %Lexicon );
+%Lexicon = ();
+
+1;
13 lib/EnhancedInclude/L10N/ja.pm
@@ -0,0 +1,13 @@
+package EnhancedInclude::L10N::ja;
+
+use strict;
+use warnings;
+
+use base 'EnhancedInclude::L10N::en_us';
+use vars qw( %Lexicon );
+
+%Lexicon = (
+ 'toi-planning' => 'ToI企画',
+);
+
+1;
Please sign in to comment.
Something went wrong with that request. Please try again.