Skip to content

Commit ac59755

Browse files
committed
Add property file usage + useAxios moving
1 parent a9621f6 commit ac59755

File tree

13 files changed

+200
-31
lines changed

13 files changed

+200
-31
lines changed

pom.xml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>io.github.jeemv.springboot.vuejs</groupId>
88
<artifactId>springboot-vuejs</artifactId>
9-
<version>1.0.8</version>
9+
<version>1.0.9</version>
1010

1111
<name>springboot-vuejs</name>
1212
<url>https://github.com/jeeMv/SpringBoot-VueJS</url>
@@ -69,6 +69,19 @@
6969
<version>5.1.0.RELEASE</version>
7070
</dependency>
7171

72+
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web -->
73+
<dependency>
74+
<groupId>org.springframework.boot</groupId>
75+
<artifactId>spring-boot-starter-web</artifactId>
76+
<version>2.1.3.RELEASE</version>
77+
</dependency>
78+
79+
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-configuration-processor -->
80+
<dependency>
81+
<groupId>org.springframework.boot</groupId>
82+
<artifactId>spring-boot-configuration-processor</artifactId>
83+
<version>2.1.3.RELEASE</version>
84+
</dependency>
7285

7386
</dependencies>
7487

src/main/java/io/github/jeemv/springboot/vuejs/VueJS.java

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,19 @@
33
import java.util.HashMap;
44
import java.util.Map;
55
import java.util.Map.Entry;
6+
7+
import javax.annotation.PostConstruct;
8+
9+
import org.slf4j.Logger;
10+
import org.slf4j.LoggerFactory;
11+
import org.springframework.beans.factory.annotation.Autowired;
12+
import org.springframework.stereotype.Component;
13+
614
import com.fasterxml.jackson.core.JsonProcessingException;
715

816
import io.github.jeemv.springboot.vuejs.components.VueComponent;
17+
import io.github.jeemv.springboot.vuejs.configuration.VueJSAutoConfiguration;
18+
import io.github.jeemv.springboot.vuejs.configuration.VueJSProperties;
919
import io.github.jeemv.springboot.vuejs.parts.AbstractVueComposition;
1020
import io.github.jeemv.springboot.vuejs.parts.VueDirective;
1121
import io.github.jeemv.springboot.vuejs.parts.VueFilter;
@@ -19,21 +29,48 @@
1929
* @version 1.0.3
2030
*
2131
*/
32+
@Component
2233
public class VueJS extends AbstractVueJS{
2334
protected String el;
2435
protected String[] delimiters;
36+
protected boolean useAxios;
2537
protected Map<String,VueComponent> globalComponents;
2638
protected Map<String,AbstractVueComposition> globalElements;
2739

40+
@Autowired(required = false)
41+
protected VueJSAutoConfiguration vueJSAutoConfiguration;
42+
private Logger logger;
43+
44+
@PostConstruct
45+
public void init() {
46+
if (null == vueJSAutoConfiguration) {
47+
logger.debug("VueJS configuration not yet loaded");
48+
} else {
49+
VueJSProperties vueJSProperties=vueJSAutoConfiguration.getVueJSProperties();
50+
setDelimiters(vueJSProperties.getPrefix(), vueJSProperties.getPostfix());
51+
if(vueJSProperties.isUseAxios()) {
52+
useAxios=true;
53+
}
54+
el=vueJSProperties.getEl();
55+
}
56+
}
57+
2858
/**
2959
* @param element the DOM selector for the VueJS application
3060
*/
3161
public VueJS(String element) {
3262
super();
3363
this.el=element;
34-
this.setDelimiters("<%", "%>");
3564
globalComponents=new HashMap<>();
3665
globalElements=new HashMap<>();
66+
logger = LoggerFactory.getLogger(VueJS.class);
67+
}
68+
69+
/**
70+
* Starts the VueJS app with v-app element
71+
*/
72+
public VueJS() {
73+
this("v-app");
3774
}
3875

3976
/**
@@ -52,6 +89,9 @@ public void setDelimiters(String start,String end) {
5289
@Override
5390
public String getScript() {
5491
String script="";
92+
if(useAxios) {
93+
script="Vue.prototype.$http = axios;\n";
94+
}
5595
try {
5696
for(Entry<String, VueComponent> entry:globalComponents.entrySet()) {
5797
script+=entry.getValue();
@@ -115,4 +155,12 @@ public void setEl(String el) {
115155
this.el = el;
116156
}
117157

158+
/**
159+
* Sets axios as library to use for $http
160+
* do not forget to include the corresponding js file
161+
*/
162+
public void setUseAxios(boolean useAxios) {
163+
this.useAxios = useAxios;
164+
}
165+
118166
}

src/main/java/io/github/jeemv/springboot/vuejs/components/VueComponent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
import org.springframework.core.io.Resource;
1515
import com.fasterxml.jackson.core.JsonProcessingException;
1616
import io.github.jeemv.springboot.vuejs.AbstractVueJS;
17-
import io.github.jeemv.springboot.vuejs.VueConfig;
1817
import io.github.jeemv.springboot.vuejs.beans.RawObject;
18+
import io.github.jeemv.springboot.vuejs.configuration.VueConfig;
1919
import io.github.jeemv.springboot.vuejs.console.CommandAction;
2020
import io.github.jeemv.springboot.vuejs.console.CommandPrompt;
2121
import io.github.jeemv.springboot.vuejs.parts.VueProps;

src/main/java/io/github/jeemv/springboot/vuejs/VueConfig.java renamed to src/main/java/io/github/jeemv/springboot/vuejs/configuration/VueConfig.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,35 @@
1-
package io.github.jeemv.springboot.vuejs;
1+
package io.github.jeemv.springboot.vuejs.configuration;
22

33
import java.util.Properties;
44

55
/**
6-
* VueConfig
6+
* VueConfig (Used for components creation)
77
* This class is part of springBoot-VueJS
88
* @author jc
99
* @version 1.0.0
1010
*
1111
*/
1212
public class VueConfig{
13+
1314
private static VueConfig instance;
1415
public static boolean debug=false;
1516
private Properties properties;
17+
1618
private VueConfig() {
1719
properties=new Properties();
1820
}
21+
1922
private static VueConfig getInstance() {
2023
if(instance==null) {
2124
instance=new VueConfig();
2225
}
2326
return instance;
2427
}
28+
2529
public static Properties getProperties() {
2630
return getInstance().properties;
2731
}
32+
2833
public static String getTemplateComponentFolder() {
2934
return getProperties().getProperty("template-component-folder","vueJS");
3035
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package io.github.jeemv.springboot.vuejs.configuration;
2+
3+
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
4+
import org.springframework.boot.context.properties.EnableConfigurationProperties;
5+
import org.springframework.context.ApplicationContext;
6+
import org.springframework.context.annotation.Configuration;
7+
import org.springframework.stereotype.Component;
8+
9+
import io.github.jeemv.springboot.vuejs.VueJS;
10+
11+
@Component
12+
@Configuration
13+
@ConditionalOnClass(VueJS.class)
14+
@EnableConfigurationProperties(VueJSProperties.class)
15+
public class VueJSAutoConfiguration {
16+
17+
private final VueJSProperties vueJSProperties;
18+
19+
private final ApplicationContext applicationContext;
20+
21+
public VueJSAutoConfiguration(VueJSProperties vueJSProperties,
22+
ApplicationContext applicationContext) {
23+
this.vueJSProperties = vueJSProperties;
24+
this.applicationContext = applicationContext;
25+
}
26+
27+
public VueJSProperties getVueJSProperties() {
28+
return vueJSProperties;
29+
}
30+
31+
public ApplicationContext getApplicationContext() {
32+
return applicationContext;
33+
}
34+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package io.github.jeemv.springboot.vuejs.configuration;
2+
3+
import org.springframework.boot.context.properties.ConfigurationProperties;
4+
import org.springframework.stereotype.Component;
5+
6+
@ConfigurationProperties(prefix = "springboot.vuejs")
7+
@Component
8+
public class VueJSProperties {
9+
public static final String DEFAULT_PREFIX = "<%";
10+
11+
public static final String DEFAULT_POSTFIX = "%>";
12+
13+
public static final String DEFAULT_ELEMENT = "v-app";
14+
15+
private String[] delimiters;
16+
private boolean axios;
17+
private String el;
18+
19+
public String[] getDelimiters() {
20+
return delimiters;
21+
}
22+
23+
public String getPrefix() {
24+
if(delimiters!=null && delimiters.length>0) {
25+
return delimiters[0];
26+
}
27+
return DEFAULT_PREFIX;
28+
}
29+
30+
public String getPostfix() {
31+
if(delimiters!=null && delimiters.length>1) {
32+
return delimiters[1];
33+
}
34+
return DEFAULT_POSTFIX;
35+
}
36+
37+
public void setEl(String el) {
38+
this.el=el;
39+
}
40+
41+
public String getEl() {
42+
if(el!=null) {
43+
return el;
44+
}
45+
return DEFAULT_ELEMENT;
46+
}
47+
48+
public void setDelimiters(String... delimiters) {
49+
this.delimiters = delimiters;
50+
}
51+
52+
public boolean isUseAxios() {
53+
return axios;
54+
}
55+
56+
public boolean getAxios() {
57+
return axios;
58+
}
59+
60+
public void setAxios(boolean axios) {
61+
this.axios = axios;
62+
}
63+
64+
/* private boolean isBooleanTrue(String value,boolean dValue) {
65+
if(value==null) {
66+
return dValue;
67+
}
68+
return "1".equals(value) || "true".equals(value);
69+
}
70+
*/
71+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
*
3+
*/
4+
/**
5+
* package-info
6+
* This class is part of springBoot-VueJS
7+
* @author jc
8+
* @version 1.0.0
9+
*
10+
*/
11+
package io.github.jeemv.springboot.vuejs.configuration;

src/main/java/io/github/jeemv/springboot/vuejs/parts/VueComputeds.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package io.github.jeemv.springboot.vuejs.parts;
22

3-
import io.github.jeemv.springboot.vuejs.VueConfig;
3+
import io.github.jeemv.springboot.vuejs.configuration.VueConfig;
44
import io.github.jeemv.springboot.vuejs.utilities.JsUtils;
55

66
public class VueComputeds extends VuePart {

src/main/java/io/github/jeemv/springboot/vuejs/parts/VueMethods.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package io.github.jeemv.springboot.vuejs.parts;
22

3-
import io.github.jeemv.springboot.vuejs.VueConfig;
3+
import io.github.jeemv.springboot.vuejs.configuration.VueConfig;
44
import io.github.jeemv.springboot.vuejs.utilities.JsUtils;
55

66
public class VueMethods extends VuePart {

src/main/java/io/github/jeemv/springboot/vuejs/parts/VueWatchers.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package io.github.jeemv.springboot.vuejs.parts;
22

3-
import io.github.jeemv.springboot.vuejs.VueConfig;
3+
import io.github.jeemv.springboot.vuejs.configuration.VueConfig;
44
import io.github.jeemv.springboot.vuejs.utilities.JsUtils;
55

66
public class VueWatchers extends VuePart {

0 commit comments

Comments
 (0)