-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from igapyon/feature_20170117a
Feature 20170117a
- Loading branch information
Showing
7 changed files
with
151 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
...ain/java/jp/igapyon/diary/v3/mdconv/freemarker/directive/LocalYearlistDirectiveModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* | ||
* Igapyon Diary system v3 (IgapyonV3). | ||
* Copyright (C) 2015-2017 Toshiki Iga | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
/* | ||
* Copyright 2015-2017 Toshiki Iga | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package jp.igapyon.diary.v3.mdconv.freemarker.directive; | ||
|
||
import java.io.BufferedWriter; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
import freemarker.core.Environment; | ||
import freemarker.template.TemplateDirectiveBody; | ||
import freemarker.template.TemplateDirectiveModel; | ||
import freemarker.template.TemplateException; | ||
import freemarker.template.TemplateModel; | ||
import jp.igapyon.diary.v3.util.IgapyonV3Settings; | ||
import jp.igapyon.diary.v3.util.SimpleDirParser; | ||
|
||
/** | ||
* ローカルの年リスト用のディレクティブモデル | ||
* | ||
* <@localyearlist /> | ||
* | ||
* @author Toshiki Iga | ||
*/ | ||
public class LocalYearlistDirectiveModel implements TemplateDirectiveModel { | ||
private IgapyonV3Settings settings = null; | ||
|
||
public LocalYearlistDirectiveModel(final IgapyonV3Settings settings) { | ||
this.settings = settings; | ||
} | ||
|
||
public void execute(final Environment env, @SuppressWarnings("rawtypes") final Map params, | ||
final TemplateModel[] loopVars, final TemplateDirectiveBody body) throws TemplateException, IOException { | ||
final BufferedWriter writer = new BufferedWriter(env.getOut()); | ||
|
||
final List<File> files = getLocalYearList(settings.getRootdir()); | ||
|
||
boolean isFirst = true; | ||
for (int index = files.size() - 1; index >= 0; index--) { | ||
if (isFirst) { | ||
isFirst = false; | ||
} else { | ||
writer.write("/ "); | ||
} | ||
|
||
final File file = files.get(index); | ||
writer.write("[" + file.getName() + "](" + settings.getBaseurl() + "/" + file.getName() + "/index.html)\n"); | ||
} | ||
|
||
writer.write("/ [ALL](" + settings.getBaseurl() + "/idxall.html)\n"); | ||
|
||
writer.flush(); | ||
} | ||
|
||
public static List<File> getLocalYearList(final File rootdir) { | ||
final SimpleDirParser parser = new SimpleDirParser() { | ||
final Pattern pat = Pattern.compile("^[0-9][0-9][0-9][0-9]$"); | ||
|
||
@Override | ||
public boolean isProcessTarget(final File file) { | ||
if (file.isDirectory() == false) { | ||
return false; | ||
} | ||
final Matcher mat = pat.matcher(file.getName()); | ||
if (mat.find()) { | ||
// 年の形式のみ対象。 | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
}; | ||
|
||
return parser.listFiles(rootdir, false); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/test/java/jp/igapyon/diary/v3/directive/DirectiveTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package jp.igapyon.diary.v3.directive; | ||
|
||
import java.io.File; | ||
|
||
import org.junit.Test; | ||
|
||
import jp.igapyon.diary.v3.mdconv.DiarySrcMd2MdConverter; | ||
import jp.igapyon.diary.v3.util.IgapyonV3Settings; | ||
|
||
public class DirectiveTest { | ||
@Test | ||
public void test() throws Exception { | ||
final IgapyonV3Settings settings = new IgapyonV3Settings(); | ||
settings.setRootdir(new File("./test/data")); | ||
new DiarySrcMd2MdConverter(settings).processDir(new File("./test/data/directive/localyearlist")); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
test/data/directive/localyearlist/test_localyearlist.html.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[top](https://igapyon.github.io/diary/) | ||
|
||
Test | ||
===================================================================================================== | ||
[![いがぴょん画像(小)](https://igapyon.github.io/diary/images/iga200306s.jpg "いがぴょん")](https://igapyon.github.io/diary/memo/memoigapyon.html) 日記形式でつづる [いがぴょん](https://igapyon.github.io/diary/memo/memoigapyon.html)コラム ウェブページです。 | ||
|
||
## Test | ||
|
||
[2017](https://igapyon.github.io/diary/2017/index.html) | ||
/ [ALL](https://igapyon.github.io/diary/idxall.html) | ||
|
||
|
||
---------------------------------------------------------------------------------------------------- | ||
|
||
## この日記について | ||
[いがぴょんについて](https://igapyon.github.io/diary/memo/memoigapyon.html) / [日記ジェネレータ](https://github.com/igapyon/igapyonv3) |
3 changes: 3 additions & 0 deletions
3
test/data/directive/localyearlist/test_localyearlist.html.src.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## Test | ||
|
||
<@localyearlist /> |