Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Frogurth committed May 10, 2012
0 parents commit c09057d
Show file tree
Hide file tree
Showing 23 changed files with 252 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .gitignore
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
4 changes: 4 additions & 0 deletions README
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`.
76 changes: 76 additions & 0 deletions project-code/app/controllers/BBCodeParser.scala
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.
18 changes: 18 additions & 0 deletions project-code/project/Build.scala
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
)

}
1 change: 1 addition & 0 deletions project-code/project/build.properties
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=0.11.2
8 changes: 8 additions & 0 deletions project-code/project/plugins.sbt
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")
Binary file added project-code/public/images/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions project-code/public/javascripts/jquery-1.7.1.min.js

Large diffs are not rendered by default.

Empty file.
7 changes: 7 additions & 0 deletions sample/.gitignore
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
4 changes: 4 additions & 0 deletions sample/README
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`.
12 changes: 12 additions & 0 deletions sample/app/controllers/Application.scala
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]"))
}

}
8 changes: 8 additions & 0 deletions sample/app/views/index.scala.html
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)

}
15 changes: 15 additions & 0 deletions sample/app/views/main.scala.html
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>
47 changes: 47 additions & 0 deletions sample/conf/application.conf
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

9 changes: 9 additions & 0 deletions sample/conf/routes
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)
18 changes: 18 additions & 0 deletions sample/project/Build.scala
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"
)

}
1 change: 1 addition & 0 deletions sample/project/build.properties
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=0.11.2
8 changes: 8 additions & 0 deletions sample/project/plugins.sbt
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")
Binary file added sample/public/images/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions sample/public/javascripts/jquery-1.7.1.min.js

Large diffs are not rendered by default.

Empty file.

0 comments on commit c09057d

Please sign in to comment.