Giter Club home page Giter Club logo

radius's Introduction

Radius – Powerful Tag-Based Templates

<img src=“https://travis-ci.org/jlong/radius.png?branch=master” alt=“Build Status” /> <img src=“https://codeclimate.com/github/jlong/radius.png” /> <img src=“https://coveralls.io/repos/jlong/radius/badge.png” alt=“Coverage Status” />

Radius is a powerful tag-based template language for Ruby inspired by the template languages used in MovableType and TextPattern. It uses tags similar to XML, but can be used to generate any form of plain text (HTML, e-mail, etc…).

Usage

With Radius, it is extremely easy to create custom tags and parse them. Here’s a small example:

require 'radius'

# Define tags on a context that will be available to a template:
context = Radius::Context.new do |c|
  c.define_tag 'hello' do
    'Hello world'
  end
  c.define_tag 'repeat' do |tag|
    number = (tag.attr['times'] || '1').to_i
    result = ''
    number.times { result << tag.expand }
    result
  end
end

# Create a parser to parse tags that begin with 'r:'
parser = Radius::Parser.new(context, :tag_prefix => 'r')

# Parse tags and output the result
puts parser.parse(%{A small example:\n<r:repeat times="3">* <r:hello />!\n</r:repeat>})

Output:

A small example:
* Hello world!
* Hello world!
* Hello world!

Quick Start

Read the QUICKSTART file to get up and running with Radius.

Requirements

Radius does not have any external requirements for using the library in your own programs.

Ragel is required to create the ruby parser from the Ragel specification, and both Ragel and Graphviz are required to draw the state graph for the parser.

Installation

It is recommended that you install Radius using the RubyGems packaging system:

% gem install --remote radius

License

Radius is released under the MIT license and is copyright © 2006-2010 John W. Long. A copy of the MIT license can be found in the LICENSE file.

Roadmap

This is a prioritized roadmap for future releases:

  1. Clean up the current code base. [Done]

  2. Add support for multi-level contexts: tags should be able to be defined to only be valid within other sets of tags. [Done]

  3. Create a simple DSL for defining contexts. [Done]

  4. Optimize for speed, modify scan.rl to emit C.

Development

The latest version of Radius can be found on RubyForge:

rubyforge.org/projects/radius

Experimental and development versions of Radius can be found on Github:

github.com/jlong/radius

If you are interested in helping with the development of Radius, feel free to fork the project on GitHub and send me a pull request.

John Long

wiseheartdesign.com

radius's People

Contributors

bkerley avatar dchelimsky avatar dergutemoritz avatar jfahrenkrug avatar jgarber avatar jlong avatar jomz avatar saturnflyer avatar steap avatar xtoddx avatar yurivm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

radius's Issues

Invalid gemspec

Hi, I noticed you had a closed issue for this on June 13, but it's doesn't appear to be resolved. Sorry I had to create another issue, my experience with commenting on a closed issues on GH is they go unanswered.

I tried installing the ruby19 branch, getting the following:

Using radius (0.7.0.prerelease) from git://github.com/jlong/radius.git (at ruby19) 
radius at /Users/.../.rvm/gems/ruby-1.9.2-p0/bundler/gems/radius-a95223efea34 did not have a valid gemspec.
This prevents bundler from installing bins or native extensions, but that may not affect its functionality.
The validation message from Rubygems was:
  ["lib/radius/parser/scan_19.rb"] are not files

My Gemfile has:

gem 'radius', :git => 'git://github.com/jlong/radius.git', :branch => 'ruby19'

I don't think the issue has anything to do with ruby-1.9.2-p0 because I have tried ruby-1.9.2-p180 and get the same result.

Short of cloning and regenerating gemspec myself I'm not sure what to do. Any advice?

Chopping other namespaced tags

The following code:

p = Radius::Parser.new
p p.parse('<fb:test>hello world</fb:test>')

outputs:

"<fb:test>hello world/fb:test>"

Radius::OrdString does not work as Nokogiri css selector

Not sure if this is the appropriate place...

I'm having an issue using RadiantCMS (unofficial branch) on Ruby 2.6 with Nokogiri 1.10.9 and Radius 0.7.5

In my case the selector is comming from Tag-Attribute which is a Radius::OrdString which breaks the Nokogiri-Selection:

selector = Radius::OrdString.new('div')
Nokogiri("<div></div>").css(selector).size

=> 0

While this works:

selector = 'div'
Nokogiri("<div></div>").css(selector).size

=> 1

Class level tags

I can't see why tags are defined each time a Context instance is created. It should be possible to define tags at class level, so speeding up application performance, since tags don't need to be created at each request.

Invalid gemspec

Hello,

I have installed latest version of radius gem from GitHun and noticed the following warning:

Using radius (0.7.0.prerelease) from https://github.com/jlong/radius.git (at master)
radius at /home/closer/.rvm/gems/ruby-1.9.2-p180@studiomobile/bundler/gems/radius-d621b8ac11e9 did not have a valid gemspec.
This prevents bundler from installing bins or native extensions, but that may not affect its functionality.
The validation message from Rubygems was:
  ["lib/radius/parser/scan.rb", "lib/radius/parser/scan.rl", "lib/radius/parser/scan_19.rb"] are not files

Thanks

ParseError messages and I18n

Can you please add I18n support in order ParseError messages could be easily translated without affecting source code in the error.rb file?

Issue with Radius tag in Ruby 1.9.2

I am using rails 2.3.11 and ruby 1.9.2 with RVM.
Ex:-
When I am passing HTML content along with the radius tag,then the Radius Parser is returning unwanted characters like \r\n and [" and multiple slashes before the double quotes.

Like :-
"<p align=\"left\">"
I am using radius gem 0.7.1.

Non-prefixed Tags

I'd like to request a feature. I'd like to be able to use Radius tags without having to set a prefix. Eg.

  parser = Radius::Parser.new(context, :tag_prefix => nil)
  puts parser.parse(%{A small example:\n<repeat times="3">* <hello />!\n</repeat>})

Is that feasible?

Ruby 1.9 support?

It looks like will not run in Ruby 1.9.1. Although I can install it cleanly from gems and git repo most tests fail. I even tried running the simple example from the README on irb but it failed to render properly:

require 'radius'
=> true

context = Radius::Context.new do |c|

  • c.define_tag 'hello' do
    
  •   'Hello world'
    
    end
    c.define_tag 'repeat' do |tag|
  •   number = (tag.attr['times'] || '1').to_i
    
    result = ''
    number.times { result << tag.expand }
    result
    end
    end
    => #<Radius::Context:0x92dc108 @definitions={"hello"=>#Proc:0x92dc040@(irb):4, "repeat"=>#Proc:0x92dbc1c@(irb):7}, @tag_binding_stack=[], @Globals=#<Radius::DelegatingOpenStruct:0x92dc090 @object=nil, @hash={}>>

parser = Radius::Parser.new(context, :tag_prefix => 'r')
=> #<Radius::Parser:0x92d5a9c @context=#<Radius::Context:0x92dc108 @definitions={"hello"=>#Proc:0x92dc040@(irb):4, "repeat"=>#Proc:0x92dbc1c@(irb):7}, @tag_binding_stack=[], @Globals=#<Radius::DelegatingOpenStruct:0x92dc090 @object=nil, @hash={}>>, @tag_prefix="r">


puts parser.parse(%{A small example:\n<r:repeat times="3">* <r:hello />!\n/r:repeat})
[#<Radius::ParseTag:0x982b2d0 @block=#Proc:0x982b2a8@/opt/ruby1.9/lib/ruby/gems/1.9.1/gems/radius-0.5.1/lib/radius.rb:413>, #<Radius::ParseContainerTag:0x982b1cc @contents=[#<Radius::ParseTag:0x982b050 @block=#Proc:0x982b028@/opt/ruby1.9/lib/ruby/gems/1.9.1/gems/radius-0.5.1/lib/radius.rb:413>], @attributes={"times"=>"3"}, @name="repeat", @block=#Proc:0x982afec@/opt/ruby1.9/lib/ruby/gems/1.9.1/gems/radius-0.5.1/lib/radius.rb:437>, #<Radius::ParseTag:0x982aec0 @block=#Proc:0x982ae98@/opt/ruby1.9/lib/ruby/gems/1.9.1/gems/radius-0.5.1/lib/radius.rb:422>]
=> nil


Any plans to support ruby 1.9? Any ideas on where it is breaking?

Thanks in advance,

Adrian Madrid

Can't close rails application by Ctrl+C

Hello,

I have noticed that the Radius has broken Rails applications closing by Ctrl+C.

Steps to reproduce:

  1. Create empty Rails 3.0.8 app
  2. Add the following string to Gemfile:

gem "radius", :git => "https://github.com/jlong/radius.git"

  1. bundle install
  2. rails s
  3. Press Ctrl+C several times.

Application continue working.

Expected behaviour:

App should be closed after Ctrl+C

Additional Information:

  • Rails 3.0.8
  • Ruby 1.9.2

Let me know if required additional information.

Thanks

License missing from gemspec

RubyGems.org doesn't report a license for your gem. This is because it is not specified in the gemspec of your last release.

via e.g.

spec.license = 'MIT'
# or
spec.licenses = ['MIT', 'GPL-2']

Including a license in your gemspec is an easy way for rubygems.org and other tools to check how your gem is licensed. As you can imagine, scanning your repository for a LICENSE file or parsing the README, and then attempting to identify the license or licenses is much more difficult and more error prone. So, even for projects that already specify a license, including a license in your gemspec is a good practice. See, for example, how rubygems.org uses the gemspec to display the rails gem license.

There is even a License Finder gem to help companies/individuals ensure all gems they use meet their licensing needs. This tool depends on license information being available in the gemspec. This is an important enough issue that even Bundler now generates gems with a default 'MIT' license.

I hope you'll consider specifying a license in your gemspec. If not, please just close the issue with a nice message. In either case, I'll follow up. Thanks for your time!

Appendix:

If you need help choosing a license (sorry, I haven't checked your readme or looked for a license file), GitHub has created a license picker tool. Code without a license specified defaults to 'All rights reserved'-- denying others all rights to use of the code.
Here's a list of the license names I've found and their frequencies

p.s. In case you're wondering how I found you and why I made this issue, it's because I'm collecting stats on gems (I was originally looking for download data) and decided to collect license metadata,too, and make issues for gemspecs not specifying a license as a public service :). See the previous link or my blog post about this project for more information.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.