Browse code

add slug

devnewton authored on 04/09/2016 08:09:15
Showing 7 changed files
... ...
@@ -1,2 +1,4 @@
1 1
 /target/
2
-/.settings/
3 2
\ No newline at end of file
3
+/.settings/
4
+/.classpath
5
+/.project
... ...
@@ -1,76 +1,81 @@
1 1
 <?xml version="1.0" encoding="UTF-8"?>
2 2
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
-         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4
-    <modelVersion>4.0.0</modelVersion>
5
-    <parent>
6
-        <groupId>org.springframework.boot</groupId>
7
-        <artifactId>spring-boot-starter-parent</artifactId>
8
-        <version>1.3.2.RELEASE</version>
9
-    </parent>
10
-    <artifactId>asciivaincra</artifactId>
11
-    <groupId>im.bci</groupId>
12
-    <name>asciivaincra</name>
13
-    <description>convert text to ascii html</description>
14
-    <version>1.0-SNAPSHOT</version>
15
-    <url>http://devnewton.bci.im</url>
16
-    <properties>
17
-        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
18
-        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
19
-    </properties>
20
-    <dependencies>
21
-        <dependency>
22
-            <groupId>org.springframework.boot</groupId>
23
-            <artifactId>spring-boot-starter</artifactId>
24
-        </dependency>
25
-        <dependency>
26
-            <groupId>pl.allegro.tech.boot</groupId>
27
-            <artifactId>handlebars-spring-boot-starter</artifactId>
28
-            <version>0.2.8</version>
29
-        </dependency>
30
-        <dependency>
31
-            <groupId>org.jsoup</groupId>
32
-            <artifactId>jsoup</artifactId>
33
-            <version>1.8.3</version>
34
-        </dependency>
35
-        <dependency>
36
-            <groupId>org.unbescape</groupId>
37
-            <artifactId>unbescape</artifactId>
38
-            <version>1.1.2.RELEASE</version>
39
-        </dependency>
40
-        <dependency>
41
-            <groupId>com.moparisthebest</groupId>
42
-            <artifactId>junidecode</artifactId>
43
-            <version>0.1.1</version>
44
-        </dependency>
45
-        <dependency>
46
-            <groupId>org.webjars</groupId>
47
-            <artifactId>jquery</artifactId>
48
-            <version>3.0.0-alpha1</version>
49
-        </dependency>
50
-    </dependencies>
51
-    <build>
52
-        <resources>
53
-            <resource>
54
-                <directory>src/main/resources</directory>
55
-                <filtering>false</filtering>
56
-                <includes>
57
-                    <include>**/*.html</include>
58
-                    <include>**/*.properties</include>
59
-                    <include>**/*.xml</include>
60
-                    <include>**/*.js</include>
61
-                    <include>**/*.css</include>
62
-                    <include>**/*.png</include>
63
-                </includes>
64
-            </resource>
65
-        </resources>
66
-        <plugins>
67
-            <plugin>
68
-                <groupId>org.springframework.boot</groupId>
69
-                <artifactId>spring-boot-maven-plugin</artifactId>
70
-                <configuration>
71
-                    <mainClass>im.bci.asciivaincra.AsciiVaincraApplication</mainClass>
72
-                </configuration>
73
-            </plugin>
74
-        </plugins>
75
-    </build>
3
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4
+	<modelVersion>4.0.0</modelVersion>
5
+	<parent>
6
+		<groupId>org.springframework.boot</groupId>
7
+		<artifactId>spring-boot-starter-parent</artifactId>
8
+		<version>1.3.2.RELEASE</version>
9
+	</parent>
10
+	<artifactId>asciivaincra</artifactId>
11
+	<groupId>im.bci</groupId>
12
+	<name>asciivaincra</name>
13
+	<description>convert text to ascii html</description>
14
+	<version>1.0-SNAPSHOT</version>
15
+	<url>http://devnewton.bci.im</url>
16
+	<properties>
17
+		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
18
+		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
19
+	</properties>
20
+	<dependencies>
21
+		<dependency>
22
+			<groupId>org.springframework.boot</groupId>
23
+			<artifactId>spring-boot-starter</artifactId>
24
+		</dependency>
25
+		<dependency>
26
+			<groupId>pl.allegro.tech.boot</groupId>
27
+			<artifactId>handlebars-spring-boot-starter</artifactId>
28
+			<version>0.2.8</version>
29
+		</dependency>
30
+		<dependency>
31
+			<groupId>org.jsoup</groupId>
32
+			<artifactId>jsoup</artifactId>
33
+			<version>1.8.3</version>
34
+		</dependency>
35
+		<dependency>
36
+			<groupId>org.unbescape</groupId>
37
+			<artifactId>unbescape</artifactId>
38
+			<version>1.1.2.RELEASE</version>
39
+		</dependency>
40
+		<dependency>
41
+			<groupId>com.moparisthebest</groupId>
42
+			<artifactId>junidecode</artifactId>
43
+			<version>0.1.1</version>
44
+		</dependency>
45
+		<dependency>
46
+			<groupId>com.github.slugify</groupId>
47
+			<artifactId>slugify</artifactId>
48
+			<version>2.1.6</version>
49
+		</dependency>
50
+		<dependency>
51
+			<groupId>org.webjars</groupId>
52
+			<artifactId>jquery</artifactId>
53
+			<version>3.0.0-alpha1</version>
54
+		</dependency>
55
+	</dependencies>
56
+	<build>
57
+		<resources>
58
+			<resource>
59
+				<directory>src/main/resources</directory>
60
+				<filtering>false</filtering>
61
+				<includes>
62
+					<include>**/*.html</include>
63
+					<include>**/*.properties</include>
64
+					<include>**/*.xml</include>
65
+					<include>**/*.js</include>
66
+					<include>**/*.css</include>
67
+					<include>**/*.png</include>
68
+				</includes>
69
+			</resource>
70
+		</resources>
71
+		<plugins>
72
+			<plugin>
73
+				<groupId>org.springframework.boot</groupId>
74
+				<artifactId>spring-boot-maven-plugin</artifactId>
75
+				<configuration>
76
+					<mainClass>im.bci.asciivaincra.AsciiVaincraApplication</mainClass>
77
+				</configuration>
78
+			</plugin>
79
+		</plugins>
80
+	</build>
76 81
 </project>
... ...
@@ -1,10 +1,6 @@
1 1
 package im.bci.asciivaincra.controllers;
2 2
 
3 3
 import im.bci.asciivaincra.converters.Converter;
4
-import org.jsoup.Jsoup;
5
-import org.jsoup.nodes.Document.OutputSettings;
6
-import org.jsoup.nodes.Entities.EscapeMode;
7
-import org.jsoup.safety.Whitelist;
8 4
 import org.springframework.ui.Model;
9 5
 import org.springframework.web.bind.annotation.RequestMapping;
10 6
 import org.springframework.web.bind.annotation.RequestMethod;
... ...
@@ -13,8 +9,6 @@ import org.springframework.web.bind.annotation.RestController;
13 9
 import im.bci.asciivaincra.frontend.ConvertMV;
14 10
 import im.bci.asciivaincra.frontend.ConvertRQ;
15 11
 import org.springframework.beans.factory.annotation.Autowired;
16
-import org.unbescape.java.JavaEscape;
17
-import org.unbescape.java.JavaEscapeLevel;
18 12
 
19 13
 @RestController
20 14
 @RequestMapping("/ajax")
21 15
new file mode 100644
... ...
@@ -0,0 +1,24 @@
1
+package im.bci.asciivaincra.converters;
2
+
3
+import im.bci.asciivaincra.frontend.ConversionType;
4
+import net.sf.junidecode.Junidecode;
5
+import org.springframework.stereotype.Component;
6
+
7
+/**
8
+ *
9
+ * @author devnewton
10
+ */
11
+@Component
12
+public class SlugConverter implements Converter {
13
+
14
+    @Override
15
+    public ConversionType getType() {
16
+        return ConversionType.TO_TXT;
17
+    }
18
+
19
+    @Override
20
+    public String convert(String text) {
21
+        return Junidecode.unidecode(text);
22
+    }
23
+
24
+}
... ...
@@ -1,9 +1,10 @@
1 1
 package im.bci.asciivaincra.converters;
2 2
 
3 3
 import im.bci.asciivaincra.frontend.ConversionType;
4
-import net.sf.junidecode.Junidecode;
5 4
 import org.springframework.stereotype.Component;
6 5
 
6
+import com.github.slugify.Slugify;
7
+
7 8
 /**
8 9
  *
9 10
  * @author devnewton
... ...
@@ -13,12 +14,13 @@ public class TxtConverter implements Converter {
13 14
 
14 15
     @Override
15 16
     public ConversionType getType() {
16
-        return ConversionType.TO_TXT;
17
+        return ConversionType.TO_SLUG;
17 18
     }
18 19
 
19 20
     @Override
20 21
     public String convert(String text) {
21
-        return Junidecode.unidecode(text);
22
+    	Slugify slugify = new Slugify();
23
+    	return slugify.slugify(text);
22 24
     }
23 25
 
24 26
 }
... ...
@@ -11,5 +11,6 @@ public enum ConversionType {
11 11
     TO_JAVASCRIPT,
12 12
     TO_JSON,
13 13
     TO_PROPERTIES,
14
+    TO_SLUG,
14 15
     TO_TXT
15 16
 }
... ...
@@ -1,39 +1,40 @@
1 1
 <!DOCTYPE html>
2 2
 <html>
3
-    <head>
4
-        <title>Ascii vaincra!</title>
5
-        <meta charset="UTF-8">
6
-        <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
-        <meta name="robots" content="noindex,nofollow">
8
-        <link rel="icon" type="image/png" href="/favicon.png">
9
-    </head>
10
-    <body>
11
-        <label for="conversion">Conversion:</label>
12
-        <select id="conversion" name="conversion">
13
-            <optgroup label="Web">
14
-                <option value="TO_HTML">to html</option>
15
-                <option value="TO_CSS">to css</option>
16
-            </optgroup>
17
-            <optgroup label="Programming">
18
-                <option value="TO_JAVA">to java</option>
19
-                <option value="TO_JAVASCRIPT">to javascript</option>
20
-            </optgroup>
21
-            <optgroup label="Data">
22
-                <option value="TO_JSON">to json</option>
23
-                <option value="TO_PROPERTIES">to properties</option>
24
-                <option value="TO_TXT">to text</option>
25
-            </optgroup>
26
-        </select>
27
-        <input id="convert" type="button" value="Convert">
28
-        <fieldset>
29
-            <legend>Input : </legend>
30
-            <textarea id="input" rows="20" cols="80"></textarea>
31
-        </fieldset>
32
-        <fieldset>
33
-            <legend>Output : </legend>
34
-            <textarea id="output" rows="20" cols="80"></textarea>
35
-        </fieldset>
36
-        <script src="/webjars/jquery/3.0.0-alpha1/jquery.js" defer></script>
37
-        <script src="/asciivaincra.js" defer></script>
38
-    </body>
3
+<head>
4
+<title>Ascii vaincra!</title>
5
+<meta charset="UTF-8">
6
+<meta name="viewport" content="width=device-width, initial-scale=1.0">
7
+<meta name="robots" content="noindex,nofollow">
8
+<link rel="icon" type="image/png" href="/favicon.png">
9
+</head>
10
+<body>
11
+	<label for="conversion">Conversion:</label>
12
+	<select id="conversion" name="conversion">
13
+		<optgroup label="Web">
14
+			<option value="TO_HTML">to html</option>
15
+			<option value="TO_CSS">to css</option>
16
+			<option value="TO_SLUG">to slug</option>
17
+		</optgroup>
18
+		<optgroup label="Programming">
19
+			<option value="TO_JAVA">to java</option>
20
+			<option value="TO_JAVASCRIPT">to javascript</option>
21
+		</optgroup>
22
+		<optgroup label="Data">
23
+			<option value="TO_JSON">to json</option>
24
+			<option value="TO_PROPERTIES">to properties</option>
25
+			<option value="TO_TXT">to text</option>
26
+		</optgroup>
27
+	</select>
28
+	<input id="convert" type="button" value="Convert">
29
+	<fieldset>
30
+		<legend>Input : </legend>
31
+		<textarea id="input" rows="20" cols="80"></textarea>
32
+	</fieldset>
33
+	<fieldset>
34
+		<legend>Output : </legend>
35
+		<textarea id="output" rows="20" cols="80"></textarea>
36
+	</fieldset>
37
+	<script src="/webjars/jquery/3.0.0-alpha1/jquery.js" defer></script>
38
+	<script src="/asciivaincra.js" defer></script>
39
+</body>
39 40
 </html>
40 41
\ No newline at end of file