Skip to content
/ w2tags Public
forked from wharsojo/w2tags

w2tags is the way to tags, a short cut / macros. when it do it use some patern define in files (HOT file) to produce tags from minimal code to become full fledge tags

License

Notifications You must be signed in to change notification settings

gl0wa/w2tags

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

W2TAGS

Run on MRI Ruby : 1.8.6 / 1.9.x

me@ubuntu:~$ sudo gem install wharsojo-w2tags

me@ubuntu:~$ w2tags -irb
ARGV  : -irb

Your W2Tags instance object stored in WH...
Ex: puts WH.parse_line("#content\n  %span Hello")
Shortcut command => wh("#content\n  %span Hello")

irb(main):001:0> wh <<END
irb(main):002:0" #wow
irb(main):003:0"   #kereen
irb(main):004:0"     . Hello World
irb(main):005:0" END
=>/usr/lib/ruby/gems/1.8/gems/wharsojo-w2tags-0.9.49/hot/erb.hot
<div id="wow">
  <div id="kereen">
    <div>Hello World</div>
  </div>
</div>
=> nil
irb(main):006:0>

DESCRIPTION:

W2Tags is the way to tags, a short cut / macros. When it do, it use some patern define in HOT file to produce tags from minimal code to become full fledge tags.

FEATURES

Before it release it use some patern, but I reliaze, today web development have some popular patern in view engine, so I change the patern. Now syntax mimics HAML to easy transisition, and proven to be useable and best.

Extended Syntax are the remain patern before I choose HAML-like syntax like “^” - NextTag (next tag will be use after using a tag like “ul” next tag “li”), Redefinition NextTag command using “~^”, define variable “&var=”, define uniq variable “@var=”, Key-Variable

"$:","*:" for attribute NAME, 
"$#","*#" for attribute ID, 
"$.","*." for attribute CLASS, 
"$@","*@" for custome attribute,
"$$" for all Key-Variable.

This Constanta will be ready every time it parse the W2TAGS HOT (% / -).

HOT file is the powerfull features in w2tags, it contains some patern that you can call it later using command “%” or “-”, it contains one or more line of html/w2tags/hot command, if you detect in you source that not DRY you can migrate the patern to HOT files and you can call it later

The rest of the command you can see in each RDOC Documentation or by reading the source of W2Tags::Parser or see in Test folder, So you can code less typing.

PROBLEMS:

Demo files

Some of Demo not yet convert to new patern so please not to tray it, I’ll do it if I have some time to do it.

Auto closing for Code

Closing tags for HAML code like:

- if <condition>

does not have automatically close so you must closing it your self with

- end

for w2erb, the HOT have definition for autoclosing and the help from method on parser “shortcut_exec(regex)”, now it can auto intelligent closing

-if index>100
  .bigger bigger than 100
-elsif index>50
  .bigger bigger than 50 but less than 100
-else
  .less less than 50

.common
  Common Tag

work around to have a closing code, you can use feature to save some patern in a hot file and use it in your code, example: “common.hot”

>>_if
- if $*
<</
- end

and use it in your code:

-if <condition>

and it do automatic closing

SYNOPSIS:

HAML Like Syntax

just use it like haml basic, and if alredy comfort with that syntax you can extend the syntax and combine it with patern definition created in hot file or you can create your own hot file.

Example 1 - HAML:

#content
  %h1 menu
  %ul
    %li menu 1
    %li menu 2

will produce

<div id="content">
  <h1>menu</h1>
  <ul>
    <li>menu 1</li>
    <li>menu 2</li>
  </ul>
</div>

Extended syntax that produce the same result

#content
  %h1 menu
  %ul
    ^ menu 1; menu 2

or if the patern is so common, it can be save in a hot file and use it as hot command. Example: inside “common.hot”

>>_ul
%ul
  ^$*

and code in source:

!hot!common
#content
  %h1 menu
  -ul menu 1; menu 2

Example 2 - Form input

HAML format:

%h1 New user

= error_messages_for :user 

-form_for @user do |f| 
  %p
    %b Name
    %br
    = f.text_field :name 
  %p
    %b Email
    %br
    = f.text_field :email 
  %p
    %b Last login
    %br
    = f.datetime_select :last_login 

  %p
    = f.submit "Create"
= link_to 'Back', users_path

You can see that it not DRY, some patern will go to HOT files “rails_basic.hot”

>>_input
%p
  %b $0.capitalize.gsub('_',' ')-
  %br
  = f.text_field :$0

>>_submit
!/
%p
  = f.submit "$0"

and code in source:

!hot!rails_basic
%h1 New user

= error_messages_for :user

-form_for @user do |f|
  -input name;email;last_login
  -submit Create

= link_to 'Back', users_path

REQUIREMENTS:

no requirement for w2tags (the parser), since it use only regular expression to do parsing.

converting .erb or .html need hpricot engine to do search tags (see below on command no.10)

INSTALL:

sudo gem install w2tags

COMMAND LINE

get it from commandline “w2tags”

 How to WaytoTags:
 ~~~~~~~~~~~~~~~~~~~~~~~
 syntax:
 w2tags [*.w2erb] [-a] [-d:*opt*]
 OR
 w2tags [file1,file2,file3] [-b] [-d:*opt*]

 example:
 1. w2tags -a             #=> translate all file with ext: w2erb
 2. w2tags *.w2erb -a     #=> translate all file with ext: w2erb
 3. w2tags file1.w2erb    #=> translate a file
 4. w2tags file1.w2erb -b #=> translate a file with no initialize/finalize
 5. w2tags file1.w2erb -d:parser #=> translate with debug parser
 6. w2tags file1.w2erb -d:constanta #=> translate with debug constanta
 7. w2tags file1.w2erb -d:stack #=> translate with debug stack indentation
 8. w2tags -try           #=> Test W2tags using Sinatra http://localhost:4567/
 9. w2tags -irb           #=> Start IRB with WH as instance object of W2Tags
10. w2tags -rails         #=> Copy w2scaffold Rails and set environment.rb
11.w2tags -tags2w         #=> Parsing erb to w2tags

 Enjoy...

RAILS HOOK

add inside file “config/environment.rb” in the bottom:

require 'w2tags'
require 'w2tags/rails_hook'

You can automatically add by using commandline “w2tags -rails”

MERB HOOK

add inside file “config/init.rb” in the bottom:

require 'w2tags'
require 'w2tags/merb_hook'

SINATRA HOOK

sinatra usualy consist only one file “main.rb”, so just add below sinatra require:

require 'w2tags'
require 'w2tags/sinatra_hook'

Copyright © 2008 - 2009 Widi Harsojo. See LICENSE for details.

About

w2tags is the way to tags, a short cut / macros. when it do it use some patern define in files (HOT file) to produce tags from minimal code to become full fledge tags

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published