Skip to content

Commit

Permalink
Added slim spring configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
UweKubosch committed Mar 22, 2023
1 parent c855b05 commit aeb2bcf
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
15 changes: 14 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
plugins {
id 'java'
id "io.spring.dependency-management" version "1.1.0"
id "org.springframework.boot" version "2.7.6"
id 'maven-publish'
id 'signing'
}

group 'no.datek'
version '0.1.1'
version '0.2.0'
final String JRUBY_VERSION = '9.3.6.0';

repositories {
mavenLocal()
mavenCentral()
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
// implementation "org.jruby:jruby:$JRUBY_VERSION"
}

java {
withJavadocJar()
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/no/datek/slim/SlimConfigurer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package no.datek.slim;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.view.script.ScriptTemplateConfigurer;
import org.springframework.web.servlet.view.script.ScriptTemplateViewResolver;

@Configuration
public class SlimConfigurer implements WebMvcConfigurer {
@Bean
public ViewResolver scriptTemplateViewResolver() {
ScriptTemplateViewResolver resolver = new ScriptTemplateViewResolver();
resolver.setPrefix("/views/");
resolver.setSuffix(".slim");
return resolver;
}

@Bean
public ScriptTemplateConfigurer jrubyConfigurer() {
ScriptTemplateConfigurer configurer = new ScriptTemplateConfigurer();
configurer.setEngineName("jruby");
configurer.setScripts("ruby/load_slim.rb");
configurer.setRenderFunction("render_slim");
return configurer;
}
}
5 changes: 3 additions & 2 deletions src/main/resources/ruby/slim_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,15 @@ def params.[](key)
application_context = rendering_context.application_context
message_source = application_context.get_bean(org.springframework.context.MessageSource.java_class)
message_source_accessor = MessageSourceAccessor.new(message_source, locale)
current_location = request.getSession().getAttribute("currentLocation")

default_context = {
_csrf: request.getAttribute('_csrf'),
application_context: application_context,
content_store: {},
ctx: request.contextPath,
current_location: request.getSession().getAttribute("currentLocation"),
currentLocation: request.getSession().getAttribute("currentLocation"),
current_location: current_location,
currentLocation: current_location,
current_user: SecurityContextHolder.context&.authentication&.principal,
locale: locale,
message: message_source_accessor,
Expand Down

0 comments on commit aeb2bcf

Please sign in to comment.