-
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.
- Loading branch information
0 parents
commit c09057d
Showing
23 changed files
with
252 additions
and
0 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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,8 @@ | |||
logs | |||
project/project | |||
project/target | |||
target | |||
tmp | |||
.history | |||
dist*.class | |||
*.iml |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,4 @@ | |||
This is your new Play 2.0 application | |||
===================================== | |||
|
|||
This file will be packaged with your application, when using `play dist`. |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,76 @@ | |||
package controllers | |||
|
|||
import scala.util.matching._ | |||
|
|||
|
|||
object BBCodeParser { | |||
implicit def stringToHtml(s: String) = new { | |||
def escape = { | |||
var html = s.replace("\n", "<br/>") | |||
.replace("[b]", "<b>").replace("[/b]", "</b>") | |||
.replace("[i]", "<i>").replace("[/i]", "</i>") | |||
.replace("[u]", "<u>").replace("[/u]", "</u>") | |||
.replace("[center]", "<center>").replace("[/center]", "</center>") | |||
|
|||
html = replaceFontWithRegex(html) | |||
html = replaceUrlAndImg(html) | |||
html = replaceList(html) | |||
|
|||
html.replace("\n", "<br/>") | |||
} | |||
} | |||
|
|||
private def replaceFontWithRegex(s: String) = { | |||
var re = s | |||
val fontRegex = new Regex("\\[font=([^\\]]+)\\]", "font") | |||
re = fontRegex replaceAllIn (re, m => "<font face=\"" + m.group("font") + "\">") replace ("[/font]", "</font>") | |||
|
|||
val colorRegex = new Regex("\\[color=([^\\]]+)\\]", "color") | |||
re = colorRegex replaceAllIn (re, m => "<font color=\"" + m.group("color") + "\">") replace ("[/color]", "</font>") | |||
|
|||
val sizeRegex = new Regex("\\[size=([^\\]]+)\\]", "size") | |||
re = sizeRegex replaceAllIn (re, m => "<font size=\"" + m.group("size") + "\">") replace ("[/size]", "</font>") | |||
re | |||
} | |||
|
|||
private def replaceUrlAndImg(s: String) = { | |||
var re = s | |||
val imageRegex = new Regex("\\[img\\](.*?)\\[/img\\]", "image") | |||
val urlRegex = new Regex("\\[url=?(.*?)\\](.*?)\\[/url\\]", "url", "text") | |||
re = imageRegex replaceAllIn (re , m => "<img source=\"" + m.group("image") + "\" alt=\"An image\"/>") | |||
re = urlRegex replaceAllIn (re, m => { | |||
var prot = "http://" | |||
if(!m.group("url").isEmpty) { | |||
if(m.group("url").startsWith("http://")) | |||
prot = "" | |||
"<a href=\"" + prot + m.group("url") + "\">" + m.group("text") + "</a>" | |||
} | |||
else { | |||
if(m.group("text").startsWith("http://")) | |||
prot = "" | |||
"<a href=\"" + prot + m.group("text") + "\">" + m.group("text") + "</a>" | |||
} | |||
}) | |||
re | |||
} | |||
|
|||
private def replaceList(s: String) = { | |||
var re = s | |||
val listRegex = new Regex("""(?s)\[list=?([1ia])?\](.*?)\[/list\]""", "opt", "content") | |||
re = listRegex replaceAllIn (re, { m => | |||
if( m.group("opt")== null || m.group("opt").isEmpty) { | |||
"<ul>" + m.group("content") + "</ul>" | |||
} else { | |||
if(m.group("opt") == "1") { | |||
"<ol>" + m.group("content") + "</ol>" | |||
} else { | |||
"<ol type=\"" + m.group("opt") + "\">" + m.group("content") + "</ol>" | |||
} | |||
} | |||
}) | |||
|
|||
val bulletRegex = new Regex("""\[\*\](.+)""", "content") | |||
|
|||
bulletRegex replaceAllIn (re, m => "<li>" + m.group("content") + "</li>") | |||
} | |||
} |
Empty file.
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,18 @@ | |||
import sbt._ | |||
import Keys._ | |||
import PlayProject._ | |||
|
|||
object ApplicationBuild extends Build { | |||
|
|||
val appName = "csn_bbcodeparser" | |||
val appVersion = "1.0-SNAPSHOT" | |||
|
|||
val appDependencies = Seq( | |||
// Add your project dependencies here, | |||
) | |||
|
|||
val main = PlayProject(appName, appVersion, appDependencies, mainLang = SCALA).settings( | |||
// Add your own project settings here | |||
) | |||
|
|||
} |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1 @@ | |||
sbt.version=0.11.2 |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,8 @@ | |||
// Comment to get more information during initialization | |||
logLevel := Level.Warn | |||
|
|||
// The Typesafe repository | |||
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/" | |||
|
|||
// Use the Play sbt plugin for Play projects | |||
addSbtPlugin("play" % "sbt-plugin" % "2.0") |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
Empty file.
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,7 @@ | |||
logs | |||
project/project | |||
project/target | |||
target | |||
tmp | |||
.history | |||
dist |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,4 @@ | |||
This is your new Play 2.0 application | |||
===================================== | |||
|
|||
This file will be packaged with your application, when using `play dist`. |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,12 @@ | |||
package controllers | |||
|
|||
import play.api._ | |||
import play.api.mvc._ | |||
|
|||
object Application extends Controller { | |||
|
|||
def index = Action { | |||
Ok(views.html.index("[i][b]Your new application is ready[/b][/i]")) | |||
} | |||
|
|||
} |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,8 @@ | |||
@(message: String) | |||
@import helper._ | |||
@import controllers.BBCodeParser._ | |||
@main("Welcome to Play 2.0") { | |||
|
|||
@Html(message.escape) | |||
|
|||
} |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,15 @@ | |||
@(title: String)(content: Html) | |||
|
|||
<!DOCTYPE html> | |||
|
|||
<html> | |||
<head> | |||
<title>@title</title> | |||
<link rel="stylesheet" media="screen" href="@routes.Assets.at("stylesheets/main.css")"> | |||
<link rel="shortcut icon" type="image/png" href="@routes.Assets.at("images/favicon.png")"> | |||
<script src="@routes.Assets.at("javascripts/jquery-1.7.1.min.js")" type="text/javascript"></script> | |||
</head> | |||
<body> | |||
@content | |||
</body> | |||
</html> |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,47 @@ | |||
# This is the main configuration file for the application. | |||
# ~~~~~ | |||
|
|||
# Secret key | |||
# ~~~~~ | |||
# The secret key is used to secure cryptographics functions. | |||
# If you deploy your application to several instances be sure to use the same key! | |||
application.secret="XYvV5ZdXgp>7@:^Et5Y=fymXajuWjTpEXaCZX1;oLVA5LQ>O9bE0RFv8_GrSds2V" | |||
|
|||
# The application languages | |||
# ~~~~~ | |||
application.langs="en" | |||
|
|||
# Global object class | |||
# ~~~~~ | |||
# Define the Global object class for this application. | |||
# Default to Global in the root package. | |||
# global=Global | |||
|
|||
# Database configuration | |||
# ~~~~~ | |||
# You can declare as many datasources as you want. | |||
# By convention, the default datasource is named `default` | |||
# | |||
# db.default.driver=org.h2.Driver | |||
# db.default.url="jdbc:h2:mem:play" | |||
# db.default.user=sa | |||
# db.default.password= | |||
|
|||
# Evolutions | |||
# ~~~~~ | |||
# You can disable evolutions if needed | |||
# evolutionplugin=disabled | |||
|
|||
# Logger | |||
# ~~~~~ | |||
# You can also configure logback (http://logback.qos.ch/), by providing a logger.xml file in the conf directory . | |||
|
|||
# Root logger: | |||
logger.root=ERROR | |||
|
|||
# Logger used by the framework: | |||
logger.play=INFO | |||
|
|||
# Logger provided to your application: | |||
logger.application=DEBUG | |||
|
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,9 @@ | |||
# Routes | |||
# This file defines all application routes (Higher priority routes first) | |||
# ~~~~ | |||
|
|||
# Home page | |||
GET / controllers.Application.index | |||
|
|||
# Map static resources from the /public folder to the /assets URL path | |||
GET /assets/*file controllers.Assets.at(path="/public", file) |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,18 @@ | |||
import sbt._ | |||
import Keys._ | |||
import PlayProject._ | |||
|
|||
object ApplicationBuild extends Build { | |||
|
|||
val appName = "bbcode_sample" | |||
val appVersion = "1.0-SNAPSHOT" | |||
|
|||
val appDependencies = Seq( | |||
"csn_bbcodeparser" % "csn_bbcodeparser_2.9.1" % "1.0-SNAPSHOT" | |||
) | |||
|
|||
val main = PlayProject(appName, appVersion, appDependencies, mainLang = SCALA).settings( | |||
resolvers += "CSN Modules Github Repository" at "csnmodules.github.com" | |||
) | |||
|
|||
} |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1 @@ | |||
sbt.version=0.11.2 |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,8 @@ | |||
// Comment to get more information during initialization | |||
logLevel := Level.Warn | |||
|
|||
// The Typesafe repository | |||
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/" | |||
|
|||
// Use the Play sbt plugin for Play projects | |||
addSbtPlugin("play" % "sbt-plugin" % "2.0") |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
Empty file.