Skip to content

Commit 03792c8

Browse files
committed
Pygments, About and PostType
1 parent 95bca27 commit 03792c8

43 files changed

Lines changed: 503 additions & 191 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
0 Bytes
Binary file not shown.
44.7 KB
Binary file not shown.
0 Bytes
Binary file not shown.
150 Bytes
Binary file not shown.
6.96 KB
Binary file not shown.

build.gradle

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apply plugin: 'war'
33
apply plugin: 'idea'
44
apply plugin: 'eclipse'
55
apply plugin: 'org.akhikhl.gretty'
6-
// apply plugin: 'spring-boot'
6+
//apply plugin: 'spring-boot'
77

88
// JDK 8
99
sourceCompatibility = 1.8
@@ -20,10 +20,13 @@ repositories {
2020
maven { url "http://repo.springsource.org/repo" } // for springloaded
2121
}
2222

23+
24+
2325
dependencies {
24-
// compile "org.springframework.boot:spring-boot-devtools"
25-
// compile("org.springframework.boot:spring-boot-starter-web")
26-
// compile "com.domingosuarez.boot:spring-boot-starter-jade4j:0.3.0"
26+
// spring boot
27+
compile("org.springframework.boot:spring-boot-starter-web")
28+
29+
// spring framework
2730
compile 'org.springframework:spring-context:4.2.1.RELEASE'
2831
compile 'org.springframework:spring-webmvc:4.1.7.RELEASE'
2932
compile 'org.springframework.security:spring-security-config:3.2.7.RELEASE'
@@ -84,6 +87,7 @@ dependencies {
8487
// compile 'org.webjars.npm:jointjs:0.9.4'
8588

8689
// test
90+
testCompile("org.springframework.boot:spring-boot-starter-test")
8791
testCompile 'junit:junit:+'
8892
testCompile 'org.mockito:mockito-core:+'
8993
testCompile 'org.assertj:assertj-core:+'
@@ -100,22 +104,37 @@ dependencies {
100104

101105
//Gretty Embedded Jetty
102106
buildscript {
107+
ext {
108+
springBootVersion = '1.2.6.RELEASE'
109+
}
110+
103111
repositories {
112+
mavenLocal()
104113
jcenter()
114+
115+
maven { url "http://repo.spring.io/release" }
116+
maven { url "http://repo.spring.io/milestone" }
117+
maven { url "http://repo.spring.io/snapshot" }
105118
}
106119

107120
dependencies {
108121
classpath 'org.akhikhl.gretty:gretty:+'
109122
classpath 'org.springframework:springloaded:1.2.4.RELEASE'
110-
classpath "org.springframework.boot:spring-boot-gradle-plugin:1.3.0.M5"
123+
classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
111124
}
112125
}
113126

127+
jar {
128+
baseName = 'spring-blog'
129+
version = '0.1'
130+
}
131+
132+
114133
// Don't use Jetty8, even it's a servlet 3.0+ container,
115134
// but not support non-jar WebApplicationInitializer scanning.
116135
// It will cause "No Spring WebApplicationInitializer types detected on classpath"
117136
gretty {
118137
port = 8080
119-
contextPath = ''
138+
contextPath = 'SpringBlog'
120139
servletContainer = 'jetty9' //tomcat7 or tomcat8
121140
}

settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
rootProject.name = 'SpringBlog'
1+
rootProject.name = 'SpringBlog'

src/main/java/com/raysmond/blog/Application.java

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.raysmond.blog;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.context.annotation.ComponentScan;
6+
import org.springframework.context.annotation.Configuration;
7+
import org.springframework.security.config.annotation.web.servlet.configuration.EnableWebMvcSecurity;
8+
9+
@SpringBootApplication
10+
public class BlogApp {
11+
12+
public static void main(String[] args) {
13+
SpringApplication.run(BlogApp.class, args);
14+
}
15+
}

src/main/java/com/raysmond/blog/admin/controllers/PostController.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
import com.raysmond.blog.models.Post;
55
import com.raysmond.blog.models.User;
66
import com.raysmond.blog.models.support.PostFormat;
7+
import com.raysmond.blog.models.support.PostStatus;
78
import com.raysmond.blog.repositories.PostRepository;
89
import com.raysmond.blog.repositories.UserRepository;
910
import com.raysmond.blog.services.MarkdownService;
11+
import com.raysmond.blog.services.PostService;
1012
import org.springframework.beans.factory.annotation.Autowired;
1113
import org.springframework.data.domain.Page;
1214
import org.springframework.data.domain.PageRequest;
@@ -34,6 +36,9 @@ public class PostController {
3436
@Autowired
3537
private MarkdownService markdown;
3638

39+
@Autowired
40+
private PostService postService;
41+
3742
@Autowired
3843
private UserRepository users;
3944

@@ -74,16 +79,11 @@ public String create(Principal principal, @Valid PostForm postForm, BindingResul
7479
model.addAttribute("postFormats", PostFormat.values());
7580
return "admin/posts_new";
7681
} else {
77-
Post post = postForm.toPost();
7882
User user = users.findByEmail(principal.getName());
79-
post.setUser(user);
80-
post.setPostStatus(Post.PostStatus.PUBLISHED);
83+
Post post = postForm.toPost();
8184

82-
if (post.getPostFormat() == PostFormat.MARKDOWN){
83-
post.setRenderedContent(markdown.renderToHtml(post.getContent()));
84-
}
85+
postService.createPost(user, post.getTitle(), post.getContent(), post.getPostFormat(), PostStatus.PUBLISHED);
8586

86-
posts.save(post);
8787
return "redirect:/admin/posts";
8888
}
8989
}
@@ -99,11 +99,8 @@ public String update(@PathVariable Long postId, @Valid PostForm postForm, Bindin
9999
post.setContent(postForm.getContent());
100100
post.setPostFormat(postForm.getPostFormat());
101101

102-
if (post.getPostFormat() == PostFormat.MARKDOWN){
103-
post.setRenderedContent(markdown.renderToHtml(post.getContent()));
104-
}
102+
postService.updatePost(post);
105103

106-
posts.save(post);
107104
return "redirect:/admin/posts";
108105
}
109106
}

0 commit comments

Comments
 (0)