lib/Dist/Zilla/Plugin/JSAN.pm

filter: Statementstmt 71.4% 5 / 7 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 80.0% 8 / 10 CC 1 SCAR 0.9
CC
1
Cov
71%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« script/shotenjin.pl ↑ Summary lib/Dist/Zilla/Plugin/JSAN/OptimizePNG.pm »
1 package Dist::Zilla::Plugin::JSAN;
2 3 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 $Dist::Zilla::Plugin::JSAN::VERSION = '0.06';
4 }
5  
6 # ABSTRACT: a plugin for Dist::Zilla for building JSAN distributions
7  
8  
9 3 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 0 ▶use Moose::Autobox;
Subroutine BEGIN: called CC=1 SCAR=2.6
11  
12 use Path::Class;
13 use Dist::Zilla::File::InMemory;
14  
15 with 'Dist::Zilla::Role::FileGatherer';
16 with 'Dist::Zilla::Role::BuildRunner';
17  
18  
19 has 'docs_markup' => (
20 isa => 'Str',
21 is => 'rw',
22 default => 'mmd'
23 );
24  
25  
26 has 'css_url' => (
27 isa => 'Str',
28 is => 'rw',
29 default => 'http://joose.it/markdown.css'
30 );
31  
32  
33 #================================================================================================================================================================================================================================================
34 sub build {
35 }
36  
37  
38 #================================================================================================================================================================================================================================================
39 sub gather_files {
40 my $self = shift;
41
42 my $markup = $self->docs_markup;
43
44 my $method = "generate_docs_from_$markup";
45
46 $self->$method();
47 }
48  
49  
50 #================================================================================================================================================================================================================================================
51 sub generate_docs_from_md {
52 my $self = shift;
53
54 require Text::Markdown;
55
56 $self->extract_inlined_docs({
57 html => \sub {
58 my ($comments, $content) = @_;
59 return (Text::Markdown::markdown($comments), 'html')
60 },
61
62 md => \sub {
63 my ($comments, $content) = @_;
64 return ($comments, 'md');
65 }
66 })
67 }
68  
69  
70 #================================================================================================================================================================================================================================================
71 sub generate_docs_from_mmd {
72 my $self = shift;
73
74 require Text::MultiMarkdown;
75
76 my $css_url = $self->css_url;
77
78 $self->extract_inlined_docs({
79 html => sub {
80 my ($comments, $content) = @_;
81 return (Text::MultiMarkdown::markdown("css: $css_url \n\n" . $comments, { document_format => 'Complete' }), 'html')
82 },
83
84 mmd => sub {
85 my ($comments, $content) = @_;
86 return ($comments, 'mmd');
87 }
88 })
89 }
90  
91  
92 #================================================================================================================================================================================================================================================
93 sub generate_docs_from_pod {
94 my $self = shift;
95
96 require Pod::Simple::HTML;
97 require Pod::Simple::Text;
98 require Pod::Select;
99
100 $self->extract_inlined_docs({
101 html => sub {
102 my ($comments, $content) = @_;
103
104 my $result = '';
105 my $parser = Pod::Simple::HTML->new;
106
107 $parser->output_string( \$result );
108
109 $parser->parse_string_document($content);
110
111 return ($result, 'html')
112 },
113
114
115 txt => sub {
116 my ($comments, $content) = @_;
117
118 my $result = '';
119 my $parser = Pod::Simple::Text->new;
120
121 $parser->output_string( \$result );
122
123 $parser->parse_string_document($content);
124
125 return ($result, 'txt')
126 },
127
128
129 pod => sub {
130 my ($comments, $content) = @_;
131
132 # XXX really extract pod using Pod::Select and temporary file
133 return ($content, 'pod');
134 }
135 })
136 }
137  
138  
139 #================================================================================================================================================================================================================================================
140 sub find_dist_packages {
141 my ($self) = @_;
142
143 return $self->zilla->files->grep(sub { $_->name =~ m!^lib/.+\.js$! });
144 }
145  
146  
147 #================================================================================================================================================================================================================================================
148 sub find_file {
149 my ($self, $file_name) = @_;
150
151 return ( $self->zilla->files->grep(sub { $_->name eq $file_name }) )->[0];
152 }
153  
154  
155 #================================================================================================================================================================================================================================================
156 sub extract_inlined_docs {
157 my ($self, $convertors) = @_;
158
159 my $markup = $self->docs_markup;
160 my $lib_dir = dir('lib');
161 my $js_files = $self->find_dist_packages;
162
163
164 foreach my $file (@$js_files) {
165 (my $separate_docs_file_name = $file->name) =~ s|\.js$|.$markup|;
166
167 my $separate_docs_file = $self->find_file($separate_docs_file_name);
168
169 my $content = $file->content;
170
171 my $docs_content = $separate_docs_file ? $separate_docs_file->content : $self->strip_doc_comments($content);
172  
173  
174 foreach my $format (keys(%$convertors)) {
175
176 #receiving formatted docs
177 my $convertor = $convertors->{$format};
178
179 my ($result, $result_ext) = &$convertor($docs_content, $content);
180
181
182 #preparing 'doc' directory for current format
183 my $format_dir = dir('doc', $format);
184
185 #saving results
186 (my $res = $file->name) =~ s|^$lib_dir|$format_dir|;
187
188 $res =~ s/\.js$/.$result_ext/;
189
190 $self->add_file(Dist::Zilla::File::InMemory->new(
191 name => $res,
192 content => $result
193 ));
194 }
195 }
196 }
197  
198  
199  
200 #================================================================================================================================================================================================================================================
201 sub strip_doc_comments {
202 my ($self, $content) = @_;
203
204 my @comments = ($content =~ m[^\s*/\*\*(.*?)\*/]msg);
205
206 return join '', @comments;
207 }
208  
209  
210  
211  
212 __PACKAGE__->meta->make_immutable;
213 no Moose;
214  
215 1;
216  
217  
218  
219 =pod
220  
221 =head1 NAME
222  
223 Dist::Zilla::Plugin::JSAN - a plugin for Dist::Zilla for building JSAN distributions
224  
225 =head1 VERSION
226  
227 version 0.06
228  
229 =head1 SYNOPSIS
230  
231 In F<dist.ini>:
232  
233 name = Sample-Dist
234 abstract = Some clever yet compact description
235
236 author = Clever Guy #1
237 author = Clever Guy #2
238 license = LGPL_3_0
239 copyright_holder = Clever Guy
240
241
242 ;=========================================================================
243 ; version provider
244
245 [Git::NextVersion]
246 first_version = 0.0.1
247
248
249 ;=========================================================================
250 ; include the link to git repo and web page
251
252 [GithubMeta]
253
254
255 ;=========================================================================
256 ; choose/generate files to include
257
258 [GatherDir]
259 [PruneCruft]
260 [License]
261
262
263 ;=========================================================================
264 ; JSAN-specific configuration
265
266 [JSAN] ; generate docs
267 docs_markup = mmd ; default
268 css_url = http://joose.it/markdown.css ; default
269
270 [JSAN::StaticDir]
271 static_dir = static ; default
272
273 [JSAN::PkgVersion]
274
275 [JSAN::ReadmeFromMD] ; should be after docs generation
276 [JSAN::InstallInstructions] ; add INSTALL file, describing the installation process
277 [JSAN::Bundle] ; after docs generation to avoid docs for bundles
278
279
280 ;=========================================================================
281 ; `npm` configuration - package.json generation
282
283 [JSAN::NPM]
284 main = lib/Task/Sample/Dist/Core
285
286 dependency = joose >= 3.14.0
287
288
289 ;=========================================================================
290 ; before release
291
292 [Git::Check]
293 [CheckChangesHasContent]
294 [ConfirmRelease]
295
296
297 ;=========================================================================
298 ; release
299
300 [JSAN::NPM::Publish] ; publish in `npm`
301 sudo = 1
302
303
304 ;=========================================================================
305 ; after release
306
307 [Git::Commit / Commit_Dirty_Files]
308
309 [Git::Tag]
310
311 [NextRelease]
312 format = %-9v %{yyyy-MM-dd HH:mm}d
313
314 [Git::Commit / Commit_Changes]
315
316 [Git::Push]
317 push_to = origin
318
319 [JSAN::GitHubDocs] ; after all commits to have clean workspace
320
321 [Twitter]
322 tweet_url = http://cleverguy.github.com/Sample-Dist
323 tweet = Released {{ '{{$DIST}}-{{$VERSION}} {{$URL}}' }}
324 hash_tags = #nodejs #npm
325  
326 =head1 DESCRIPTION
327  
328 This is a plugin for distribution-management tool L<Dist::Zilla>. It greatly simplifies the release process,
329 allowing you to focus on the code itself.
330  
331 =head1 PLUGINS
332  
333 Any usual Dist::Zilla plugins can be used. In the SYNOPSIS above we've used L<Dist::Zilla::Plugin::Git::Check> and L<Dist::Zilla::Plugin::CheckChangesHasContent>.
334 Additionally several JSAN-specific plugins were added:
335  
336 L<Dist::Zilla::Plugin::JSAN::Bundle> - concatenate individual source files into bundles, based on information from Components.JS file
337  
338 L<Dist::Zilla::Plugin::JSAN::StaticDir> - moves the content of the static directory to the distribution folder
339  
340 L<Dist::Zilla::Plugin::JSAN::GitHubDocs> - updates the `gh-pages` branch with the documentation after each release
341  
342 L<Dist::Zilla::Plugin::JSAN::NPM> - generate `package.json` file for your distribution
343  
344 L<Dist::Zilla::Plugin::JSAN::NPM::Publish> - publish your distribution in `npm`
345  
346 L<Dist::Zilla::Plugin::JSAN::PkgVersion> - embed version number in the source files
347  
348 L<Dist::Zilla::Plugin::JSAN::ReadmeFromMD> - copies a main documentation file to the distribution root as README.md
349  
350 L<Dist::Zilla::Plugin::JSAN::InstallInstructions> - generates INSTALL file in the root of distribution with installation instructions
351  
352 =head1 STARTING A NEW DISTRIBUTION
353  
354 This plugin allows you to easily start a new JSAN distribution. Read L<Dist::Zilla::Plugin::JSAN::Minter> to know how.
355  
356 =head1 AUTHOR
357  
358 Nickolay Platonov, C<< <nplatonov at cpan.org> >>
359  
360 =head1 BUGS
361  
362 Please report any bugs or feature requests to L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Dist-Zilla-Plugin-JSAN> or
363 L<http://github.com/SamuraiJack/Dist-Zilla-Plugin-JSAN/issues>.
364 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
365  
366 =head1 SOURCES
367  
368 This module is stored in an open repository at the following address:
369  
370 L<http://github.com/SamuraiJack/Dist-Zilla-Plugin-JSAN>
371  
372 =head1 COPYRIGHT & LICENSE
373  
374 Copyright 2010 Nickolay Platonov, all rights reserved.
375  
376 This program is free software; you can redistribute it and/or modify it
377 under the same terms as Perl itself.
378  
379 =head1 AUTHOR
380  
381 Nickolay Platonov <nplatonov@cpan.org>
382  
383 =head1 COPYRIGHT AND LICENSE
384  
385 This software is copyright (c) 2011 by Nickolay Platonov.
386  
387 This is free software; you can redistribute it and/or modify it under
388 the same terms as the Perl 5 programming language system itself.
389  
390 =cut
391  
392  
393 __END__
« script/shotenjin.pl ↑ Summary lib/Dist/Zilla/Plugin/JSAN/OptimizePNG.pm »