]> git.wincent.com - wikitext.git/log
wikitext.git
12 years agoAuto-initialize under Rails 3
Wincent Colaiuta [Sat, 12 Jun 2010 18:47:30 +0000 (20:47 +0200)] 
Auto-initialize under Rails 3

Under Rails 2 we get free auto-initialization behavior by including a
"rails/init.rb" file in our gem.

Under Rails 3 things have changed as described here:

  http://railsdispatch.com/posts/how-rails-3-enables-more-choices-part-1

Rails will effectively do a:

  require 'wikitext'

Early on in the application boot process. In our case, that effectively
means that the code in the C extension's Init_wikitext() function will
be evaluated.

So, in this commit, we replicate in C what we would have done in the
following manner if the Wikitext gem were just a pure Ruby project:

  if Object.const_defined? :ActiveSupport
    # we are running under Rails
    require 'wikitext/nil_class'
    require 'wikitext/string'

    if ActiveSupport.respond_to? :on_load
      # running under Rails 3
      ActiveSupport.on_load :action_view do
        require 'wikitext/rails_template_handler'
      end
    else
      # running under Rails 2
      require 'wikitext/rails_template_handler'
    end

Note that because one of the code paths involves passing in a block, we
have to define a couple of ancilliary helper functions and use
rb_iterate() to achieve the same effect in C.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
12 years agoSplit String#wikitext_preprocess into a separate file
Wincent Colaiuta [Sat, 12 Jun 2010 16:08:10 +0000 (18:08 +0200)] 
Split String#wikitext_preprocess into a separate file

This has always been a bit of a wart, the fact that what is essentially
an application-specific preprocessing pass was included in our
"wikitext/strings" file.

Now, if you want the behavior you have to explicitly require
'wikitext/preprocess'.

As a side effect of this change, the file now serves as a nice example
of how to implement a custom preprocessing phase if you need it.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
12 years agorails/init.rb: trust LOAD_PATH
Wincent Colaiuta [Sat, 12 Jun 2010 15:46:55 +0000 (17:46 +0200)] 
rails/init.rb: trust LOAD_PATH

Rather than doing requires with absolute paths, trust the calling
environment (in this case, Rails 2) to set up the LOAD_PATH
appropriately.

This saves us later on re-requiring the same file with a different,
relative path and needlessly re-evaluating the same code.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
12 years agoRename rails.rb to rails_template_handler.rb
Wincent Colaiuta [Sat, 12 Jun 2010 15:43:47 +0000 (17:43 +0200)] 
Rename rails.rb to rails_template_handler.rb

To avoid confusion with "rails/init.rb" file elsewhere in the repo.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
12 years agoFit "compile" method onto 1 line
Wincent Colaiuta [Sat, 12 Jun 2010 15:37:04 +0000 (17:37 +0200)] 
Fit "compile" method onto 1 line

Signed-off-by: Wincent Colaiuta <win@wincent.com>
12 years agodoc: initial updates for forthcoming 2.0 release
Wincent Colaiuta [Fri, 11 Jun 2010 16:49:39 +0000 (18:49 +0200)] 
doc: initial updates for forthcoming 2.0 release

Signed-off-by: Wincent Colaiuta <win@wincent.com>
12 years agoEmit <code> rather than <tt> elements
Wincent Colaiuta [Fri, 11 Jun 2010 16:33:55 +0000 (18:33 +0200)] 
Emit <code> rather than <tt> elements

The <tt> element has been dropped from HTML5 and the recommendation is
to instead use more "semantic" elements such as <code>, <samp> and
<kbd>. As one of the major goals for the 2.0 release is to emit valid
HTML5, the <tt> element has to go.

Given that we are working with wikitext markup and the focus is on
simplicity, we won't be adding new syntax to enable the user to control
which of the three "semantic" tag alternatives is emitted.

Instead, we maintain the existing input markup options (that is,
backticks and <tt> elements will continue to be recognized) to maintain
compatibility with existing bodies of wikitext markup, and we choose
one of the three possible elements as a replacement for <tt>.

In the end, we're going with <code> because it seems to be the most
frequently used in the terrain where the wikitext module is used (online
wikis). A customization option to override this choice could be added in
the future, but I honestly don't expect there to be any demand for it.
Likewise, explicit support for <samp> and <kbd> tags could be added, but
I doubt there'll ever be a call for it, as the whole point of working in
wikitext markup is to have an easy-to-use format and not have to write
HTML tags.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
12 years agoRun Rails specs against many more versions of Rails 2
Wincent Colaiuta [Thu, 10 Jun 2010 18:41:05 +0000 (20:41 +0200)] 
Run Rails specs against many more versions of Rails 2

Previously we only ran against Rails 2.2.2 (the latest release at the
time the specs were written) and Rails "Edge".

In this commit we extend that to run against all versions of Rails 2
put out since the release of 2.2.2. The only exception to this is
version 2.3.0, which is marked as pending because it throws a Rack
exception. I am not sure if the version of Rack bundled with 2.3.0 has
some kind of bug, or this is an interaction with the versions of Rack
that are on my system (1.0.1 and 1.1.0) and might be getting
inadvertently pulled into the tests.

Note that we don't bother running the specs against versions of Rails
older than 2.2.2, because that came out in November 2008, and there is
not much sense in retroactively extending compatibility even further
backwards in time.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
12 years agoRestore template handler functionality in Rails 2
Wincent Colaiuta [Thu, 10 Jun 2010 17:55:47 +0000 (19:55 +0200)] 
Restore template handler functionality in Rails 2

As noted in commit 3fd2ea3, we fixed template handlers for Rails 3 but
did so at the expense of support for Rails 2.

This commit adds back the old Rails 2 code path as a fallback for when
the new code path is tried and fails in the absence of Rails 3.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
12 years agoMove to Rails 3 template UI
Wincent Colaiuta [Wed, 9 Jun 2010 21:33:32 +0000 (23:33 +0200)] 
Move to Rails 3 template UI

It seems that under Rails 3 the old "self.call" method no longer works
in the same fashion. Previously returning the string "template.source.w"
worked because Rails, evidently, ended up eval'ing it in a context where
"template" resolved to the desired object.

In Rails 3, however, this is no longer the case, and it ends up trying
to call a "template" method on the controller, failing.

Googling for different template handlers shows that some use "render"
(for example, liquid) but I am unable to get any variant of "render" to
work under Rails 3.

On the other hand, the three handlers included with Rails itself (ERB,
Builder, and RJS) all use the "compile" method, as does Haml.

It's hard to tell from the scant in-code documentation, but it looks
like "compile" might be "the" supported way to write template handlers
for now. The only reference I can find to this online is this thread
from back in 2008:

  http://www.ruby-forum.com/topic/159810

In which Josh Peek says:

  I'd really like deprecate the TemplateHandler#render all together. If
  you think your handler can not be compiled, you always just compile in
  a delegate call to your "noncompilable" handler. This leaves us with
  only one method, compile.

So I am not sure if this is the "official" stance on the API, but in
light of the fact that I can't get anything else to work, I am going to
go with "compile" for now.

This unfortunately requires a somewhat ugly gsub call in order to escape
any single quotes that might be in the input, but it seems a necessary
evil. For example, a template with this wikitext markup:

  * don't you like this list?

Will be "compiled" to:

  '<ul>
    <li>don\'t you like this list?<li>
  </ul>
  '

Which when evaluated and emitted to the output steam becomes:

  <ul>
    <li>don't you like this list?</li>
  </ul>

Note that this commit makes things work with Rails 3 only, breaking
Rails 2 support. In a subsequent commit I plan to add in a conditional
code path that kicks in when running under Rails 2.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
12 years agoBump version number post-release maint
Wincent Colaiuta [Wed, 9 Jun 2010 20:12:00 +0000 (22:12 +0200)] 
Bump version number post-release

Signed-off-by: Wincent Colaiuta <win@wincent.com>
12 years agoBump version number for 1.12 release 1.12
Wincent Colaiuta [Wed, 9 Jun 2010 20:08:56 +0000 (22:08 +0200)] 
Bump version number for 1.12 release

Signed-off-by: Wincent Colaiuta <win@wincent.com>
12 years agoUpdate release notes for 1.12 release
Wincent Colaiuta [Wed, 9 Jun 2010 20:04:41 +0000 (22:04 +0200)] 
Update release notes for 1.12 release

Signed-off-by: Wincent Colaiuta <win@wincent.com>
12 years agoMark String#w and String#to_wikitext output as HTML safe
Wincent Colaiuta [Wed, 9 Jun 2010 19:33:58 +0000 (21:33 +0200)] 
Mark String#w and String#to_wikitext output as HTML safe

This applies only when running under Rails 3, or when the "html_safe"
method is otherwise available.

As these methods are the most commonly used methods for translating
wikitext markup to HTML in Rails applications, this should provide a
fairly convenient upgrade path for developers moving from Rails 2 to
Rails 3.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
12 years agoBump version number post-release
Wincent Colaiuta [Sun, 25 Apr 2010 22:20:19 +0000 (00:20 +0200)] 
Bump version number post-release

Signed-off-by: Wincent Colaiuta <win@wincent.com>
12 years agoBump version number for 1.11 release 1.11
Wincent Colaiuta [Sun, 25 Apr 2010 22:11:35 +0000 (00:11 +0200)] 
Bump version number for 1.11 release

Signed-off-by: Wincent Colaiuta <win@wincent.com>
12 years agoRakefile: Add missing ".gem" extension to "gem push" invocation
Wincent Colaiuta [Sun, 25 Apr 2010 22:13:05 +0000 (00:13 +0200)] 
Rakefile: Add missing ".gem" extension to "gem push" invocation

Signed-off-by: Wincent Colaiuta <win@wincent.com>
12 years agoRakefile: simplify spec task by shelling out
Wincent Colaiuta [Sun, 25 Apr 2010 22:02:57 +0000 (00:02 +0200)] 
Rakefile: simplify spec task by shelling out

Just run "spec spec" directly rather than depending on special support
and configuration from RSpec's "spec" Rake task.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
12 years agoAdd spec.opts file
Wincent Colaiuta [Sun, 25 Apr 2010 22:00:15 +0000 (00:00 +0200)] 
Add spec.opts file

This provides colorized output etc when running "spec spec" from the
command line.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
12 years agoMake specs non-executable
Wincent Colaiuta [Sun, 25 Apr 2010 21:58:02 +0000 (23:58 +0200)] 
Make specs non-executable

These were originally intended to be run independently as Ruby scripts,
but in practice they are only run using the "spec" tool, so remove the
bang line and unset the executable bit.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
12 years agoUse wikitext/rails as a substitute for rails/init
Wincent Colaiuta [Sun, 25 Apr 2010 20:12:06 +0000 (22:12 +0200)] 
Use wikitext/rails as a substitute for rails/init

Seeing as it seems that Rails 3 and Bundler no longer automatically
execute the "rails/init" file, users will now have to require
"wikitext/rails" if they want to get the functionality that was
previously activated from the "rails/init" file.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
12 years agoUpdate documentation for 1.11 release
Wincent Colaiuta [Sun, 25 Apr 2010 19:54:12 +0000 (21:54 +0200)] 
Update documentation for 1.11 release

Signed-off-by: Wincent Colaiuta <win@wincent.com>
12 years agoAdd wikitext_wrapper executable
Wincent Colaiuta [Sun, 25 Apr 2010 19:36:54 +0000 (21:36 +0200)] 
Add wikitext_wrapper executable

As mentioned in commit 4488c7b, in the library files we trust either the
packaging system (usually RubyGems) or the user to correctly set up the
LOAD_PATH so that all files will be found when included using simple
relative paths like "wikitext/version" and so on.

The specs and benchmarking scripts already explcitly set the LOAD_PATH
and use absolute paths where appropriate to ensure that the local
version is tested rather than some other version that might be installed
elsewhere on the system.

This commit addresses the last missing piece of the puzzle, the
"bin/wikitext" executable. That was also changed to trust the LOAD_PATH
and use shorter relative paths, and this will work for the installed
case because the packaging system (RubyGems) will actually set up a
wrapper in the user's PATH which sets up the LOAD_PATH appropraitely.

In local testing however, no such wrapper script is in place so trying
to run "bin/wikitext" will either fail (when no version is installed on
the system in th PATH) or will most likely use the wrong version (when
another version is found elsewhere).

So, for the purposes of local testing we here add a wrapper script that
achieves the same affect as the wrapper created by RubyGems during
installation: we set up a local LOAD_PATH and then fire off the real
executable.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
12 years agoUse relative paths in "require" statements
Wincent Colaiuta [Sun, 25 Apr 2010 19:25:02 +0000 (21:25 +0200)] 
Use relative paths in "require" statements

Trust the packaging system (usually RubyGems) to set up the LOAD_PATH
appropriately, thus allowing us to use cleaner and simpler "require"
startements.

Note that the spec suite already explicitly sets up the LOAD_PATH so
that the version in the current working directory is tested and not any
other versions which may be installed elsewhere on the system.

The "bin/wikitext" executable, however, doesn't do any special setup so
it will use the installed version if it is found first in the load-path.
This isn't a problem for real installs because the packaging system (ie
RubyGems) sets up an appropriate wrapper executable to set up the
LOAD_PATH first. (For local testing, I still need to set up such a
wrapper.)

Signed-off-by: Wincent Colaiuta <win@wincent.com>
12 years agoRemove repeated calls to expand_path
Wincent Colaiuta [Sun, 25 Apr 2010 18:45:57 +0000 (20:45 +0200)] 
Remove repeated calls to expand_path

Signed-off-by: Wincent Colaiuta <win@wincent.com>
12 years agoRakefile: run "make" target before "gem build"
Wincent Colaiuta [Mon, 19 Apr 2010 20:53:56 +0000 (22:53 +0200)] 
Rakefile: run "make" target before "gem build"

This is the reincarnation of commit 829011d, which fixed a subtle
problem with a missing file in the built gem.

We basically have to make sure that we've run the "make" target so that
all of the C files, including the Ragel-generated C file, is present in
the directory at the time "gem build" is called.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
12 years agogemspec: remove dependency on rake/gempackagetask
Wincent Colaiuta [Mon, 19 Apr 2010 20:42:20 +0000 (22:42 +0200)] 
gemspec: remove dependency on rake/gempackagetask

We don't need any of the bells and whistles of Rake's FileList, so can
just use Dir[].

Signed-off-by: Wincent Colaiuta <win@wincent.com>
12 years agogemspec: use more precise FileList specfication
Wincent Colaiuta [Mon, 19 Apr 2010 20:36:01 +0000 (22:36 +0200)] 
gemspec: use more precise FileList specfication

Make sure that any crud (things like .DS_Store files) that might be on
the filesystem doesn't get included in the gem.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
12 years agogemspec: update homepage attribute
Wincent Colaiuta [Mon, 19 Apr 2010 20:34:23 +0000 (22:34 +0200)] 
gemspec: update homepage attribute

There is still nothing very interesting on the Wikitext product page at
wincent.com, but it is still a more permanent home than rubyforge.org is
likely to be in the long term.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
12 years agoExtract gemspec out into separate file
Wincent Colaiuta [Mon, 19 Apr 2010 20:31:16 +0000 (22:31 +0200)] 
Extract gemspec out into separate file

As recommended here for compatibility with Bundler's "install from Git
repo" feature:

  http://yehudakatz.com/2010/04/02/using-gemspecs-as-intended/

Note that while there is some disagreement in the comments on that post
about whether this is a clever or correct thing to do, in the present
case we are merely extracting the hand-edited gemspec out into a
separate file, not "checking in a generated file into the repo".

The change seems justified because it buys us compatibility with a
Bundler feature at no real cost.

Likewise, the other main complaint raised on a different post on the
same blog (ie. that building from Git repos can run into complications
where you end up with two different gems with different code but the
same version number) doesn't apply here because I have always used a
sane version numbering scheme, bumping the version number after each
release, so a released gem will never have the same version as an
intermediate version built directly from the repo:

  http://yehudakatz.com/2010/04/12/some-of-the-problems-bundler-solves/

Signed-off-by: Wincent Colaiuta <win@wincent.com>
12 years agoBump version number post-release
Wincent Colaiuta [Sun, 21 Mar 2010 19:22:06 +0000 (20:22 +0100)] 
Bump version number post-release

Signed-off-by: Wincent Colaiuta <win@wincent.com>
12 years agoFix CSS class of explicit mailto: URIs 1.10.1
Wincent Colaiuta [Sun, 21 Mar 2010 19:01:55 +0000 (20:01 +0100)] 
Fix CSS class of explicit mailto: URIs

Previously we only correctly handled "mailto" links when the link target
itself included the "mailto:" prefix.

In other cases, where the prefix was passed in separately, for example,
we did not apply the special CSS class.

Now we always check both the link target and the prefix to see if either
of them begins with "mailto:".

Fixes the spec failures reported in:

  https://wincent.com/issues/1389

Signed-off-by: Wincent Colaiuta <win@wincent.com>
12 years agoRebuild with Ragel 6.6
Wincent Colaiuta [Sun, 21 Mar 2010 17:54:20 +0000 (18:54 +0100)] 
Rebuild with Ragel 6.6

Signed-off-by: Wincent Colaiuta <win@wincent.com>
12 years agoDeclare development dependencies in gemspec
Wincent Colaiuta [Sun, 21 Mar 2010 17:38:01 +0000 (18:38 +0100)] 
Declare development dependencies in gemspec

Signed-off-by: Wincent Colaiuta <win@wincent.com>
12 years agoFix builds on 64-bit Darwin platforms
Wincent Colaiuta [Sun, 21 Mar 2010 17:32:57 +0000 (18:32 +0100)] 
Fix builds on 64-bit Darwin platforms

Way back in ancient history when wikitext still used an ANTLR-generated
lexer, the evil commit 7a510102 added a horrible specific ARCHFLAGS
override to overcome the fact that ANTLR didn't produce Universal
binaries.

This worked fine on 32-bit machines, and the evil commit was allowed to
persist through the codebase for over two years, long after ANTLR was
ripped out and replaced with the vastly superior Ragel-generated lexer.

Today on testing on a 64-bit Darwin machine for the first time I
discovered the evil, and this commit expurgates it.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
12 years agoBump version number post-release
Wincent Colaiuta [Sun, 1 Nov 2009 15:59:37 +0000 (16:59 +0100)] 
Bump version number post-release

Signed-off-by: Wincent Colaiuta <win@wincent.com>
12 years agoBump version number for 1.10 release 1.10
Wincent Colaiuta [Sun, 1 Nov 2009 14:59:49 +0000 (15:59 +0100)] 
Bump version number for 1.10 release

Signed-off-by: Wincent Colaiuta <win@wincent.com>
12 years agoUpdate release notes for 1.10 release
Wincent Colaiuta [Sun, 1 Nov 2009 14:57:26 +0000 (15:57 +0100)] 
Update release notes for 1.10 release

Signed-off-by: Wincent Colaiuta <win@wincent.com>
12 years agoTeach wikitext tool to accept file arguments
Wincent Colaiuta [Sun, 1 Nov 2009 13:26:55 +0000 (14:26 +0100)] 
Teach wikitext tool to accept file arguments

If additional arguments are supplied they will be interpreted as
files to be processed in non-interactive mode (and any input on STDIN
will be ignored).

This is the final part of ticket #1399; see:

  https://wincent.com/issues/1399

Signed-off-by: Wincent Colaiuta <win@wincent.com>
12 years agoMove command-line tool code inside Wikitext::Tool namespace
Wincent Colaiuta [Sun, 1 Nov 2009 12:56:22 +0000 (13:56 +0100)] 
Move command-line tool code inside Wikitext::Tool namespace

This keeps the methods declared in the file out of the global namespace.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
12 years agoDon't require highline unless running in interactive mode
Wincent Colaiuta [Sun, 1 Nov 2009 12:50:40 +0000 (13:50 +0100)] 
Don't require highline unless running in interactive mode

Signed-off-by: Wincent Colaiuta <win@wincent.com>
13 years agoAdd non-interactive (piping) mode
Wincent Colaiuta [Sat, 19 Sep 2009 10:16:05 +0000 (12:16 +0200)] 
Add non-interactive (piping) mode

If input is from a pipe or output is to a pipe we enter non-interactive
mode and just process the input from STDIN and send it to STDOUT without
any prompts, looping, or colorization.

This is a partial implementation of the feature requested here:

  https://wincent.com/issues/1399

(The remaining part is to also accept filename arguments as a means of
entering non-interactive mode.)

Signed-off-by: Wincent Colaiuta <win@wincent.com>
13 years agoDon't require rubygems unless loading highline library fails
Wincent Colaiuta [Sat, 19 Sep 2009 09:58:25 +0000 (11:58 +0200)] 
Don't require rubygems unless loading highline library fails

Don't depend on rubygems unless necessary.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
13 years agoPrint version when launching wikitext executable
Wincent Colaiuta [Sat, 19 Sep 2009 09:57:01 +0000 (11:57 +0200)] 
Print version when launching wikitext executable

Signed-off-by: Wincent Colaiuta <win@wincent.com>
13 years agoInclude "wikitext" executable in Gem distribution
Wincent Colaiuta [Sat, 19 Sep 2009 09:47:43 +0000 (11:47 +0200)] 
Include "wikitext" executable in Gem distribution

The "wikitext" command-line tool has been in the repository for quite a
while, but never included in the Gem distribution. Included by user
request; see:

  https://wincent.com/issues/1398

Signed-off-by: Wincent Colaiuta <win@wincent.com>
13 years agoBump version number post-release
Wincent Colaiuta [Thu, 6 Aug 2009 12:36:53 +0000 (14:36 +0200)] 
Bump version number post-release

Signed-off-by: Wincent Colaiuta <win@wincent.com>
13 years agoBump version number for 1.9 release 1.9
Wincent Colaiuta [Thu, 6 Aug 2009 12:35:10 +0000 (14:35 +0200)] 
Bump version number for 1.9 release

Signed-off-by: Wincent Colaiuta <win@wincent.com>
13 years agoUpdate RDoc for new "link_proc" feature
Wincent Colaiuta [Thu, 6 Aug 2009 12:33:46 +0000 (14:33 +0200)] 
Update RDoc for new "link_proc" feature

Signed-off-by: Wincent Colaiuta <win@wincent.com>
13 years agoRemove repetition of ID2SYM() and rb_intern()
Wincent Colaiuta [Thu, 6 Aug 2009 12:14:21 +0000 (14:14 +0200)] 
Remove repetition of ID2SYM() and rb_intern()

Use a couple of temporary variables to avoid the ugly repeated calls to
ID2SYM() and rb_intern() with exactly the same parameters each time.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
13 years agoSilence compiler warning in StringValue
Wincent Colaiuta [Thu, 6 Aug 2009 12:11:21 +0000 (14:11 +0200)] 
Silence compiler warning in StringValue

Our use of "StringValue(j)", where "j" is of type "long" and the macro
wants a value of type "VALUE" ("unsigned long") produce a warning that
"pointer targets in passing argument 1 of ‘rb_string_value’ differ in
signedness".

Merely casting ("StringValue((VALUE)j)") doesn't work because
"StringValue" itself is a macro and produces this warning: "argument to
'&' not really an lvalue; this will be a hard error in the future".

So use a temporary variable to suppress the warning without having to
use a cast inside the macro.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
13 years agoImplement "link_proc" option ("red link" support)
Wincent Colaiuta [Thu, 23 Jul 2009 20:41:27 +0000 (22:41 +0200)] 
Implement "link_proc" option ("red link" support)

Signed-off-by: Wincent Colaiuta <win@wincent.com>
13 years agoAccept optional options hash on "nil.w"
Wincent Colaiuta [Fri, 19 Jun 2009 11:04:29 +0000 (13:04 +0200)] 
Accept optional options hash on "nil.w"

This can help us to avoid constructs like:

  text = attribute.empty? ? '' : attribute.w(:base_heading_level => 3)

We can instead just use:

  text = attribute.w :base_heading_level => 3

Signed-off-by: Wincent Colaiuta <win@wincent.com>
13 years agoUse fixed-width markup in release notes for class names etc
Wincent Colaiuta [Wed, 27 May 2009 15:49:24 +0000 (17:49 +0200)] 
Use fixed-width markup in release notes for class names etc

Make things more consistent with the rest of the documentation by using
fixed-width font markup for CSS class names and HTML tags in the release
notes (rather than using double quotes).

Signed-off-by: Wincent Colaiuta <win@wincent.com>
13 years agoRemove "not yet released" label from 1.8 heading in release notes
Wincent Colaiuta [Wed, 27 May 2009 15:48:03 +0000 (17:48 +0200)] 
Remove "not yet released" label from 1.8 heading in release notes

Signed-off-by: Wincent Colaiuta <win@wincent.com>
13 years agoBump version number post-release
Wincent Colaiuta [Wed, 27 May 2009 15:45:35 +0000 (17:45 +0200)] 
Bump version number post-release

Signed-off-by: Wincent Colaiuta <win@wincent.com>
13 years agoBump version number for 1.8 release 1.8
Wincent Colaiuta [Wed, 27 May 2009 15:39:34 +0000 (17:39 +0200)] 
Bump version number for 1.8 release

Signed-off-by: Wincent Colaiuta <win@wincent.com>
13 years agoUpdate release notes for version 1.8
Wincent Colaiuta [Wed, 27 May 2009 15:38:29 +0000 (17:38 +0200)] 
Update release notes for version 1.8

Signed-off-by: Wincent Colaiuta <win@wincent.com>
13 years agoUpdate README for new PRE_START "lang" attribute
Wincent Colaiuta [Tue, 26 May 2009 20:28:18 +0000 (22:28 +0200)] 
Update README for new PRE_START "lang" attribute

Document the use of the "lang" attribute in PRE_START tags. Note that
contrary to what is said in the commit message for 024870e, uppercase
letters are in fact allowed in the attribute value.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
13 years agoHandle optional "lang" attribute in PRE_START tags
Wincent Colaiuta [Tue, 26 May 2009 20:03:31 +0000 (22:03 +0200)] 
Handle optional "lang" attribute in PRE_START tags

In addition to the literal "<pre>" tag syntax accept a special syntax
which includes a "lang" attribute. This is used to markup a PRE_START
for syntax highlighting as a particular language; for example:

  <pre lang="ruby">def hello to="world"
    puts "Hello, #{to}"
  end</pre>

Would be translated to:

  <pre class="ruby-syntax">def hello to=&quot;world&quot;
    puts &quot;Hello, #{to}&quot;
  end</pre>

Note that language names must consist only of lower-case letters, and
"-syntax" is automatically appended, to prevent users from inserting
totally arbitrary CSS class names into the translated output. This means
that names like "ruby" and "c" will work, but that names like "obj-c" or
"ObjC" would have to be written as "objc".

In this implementation the required format for the PRE_START tag is very
strict; no excess whitespace is allowed within the tag. This has the
benefit that it is simple and fast, and doesn't require re-scanning the
token to see exactly where the value of the "lang" attribute begins and
ends.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
13 years agoExtract repeated pattern into wiki_append_pre_start()
Wincent Colaiuta [Tue, 26 May 2009 19:30:22 +0000 (21:30 +0200)] 
Extract repeated pattern into wiki_append_pre_start()

This refactoring will make it easier to add code to handle CSS classes
in PRE_START tags (for syntax highlighting).

Signed-off-by: Wincent Colaiuta <win@wincent.com>
13 years agoReally change license header
Wincent Colaiuta [Thu, 21 May 2009 19:13:34 +0000 (21:13 +0200)] 
Really change license header

90de8af corrected the license header in the generated C file rather than
the Ragel source (I need to add an "rl" filetype to Ack so that I won't
overlook this kind of thing in the future).

Signed-off-by: Wincent Colaiuta <win@wincent.com>
13 years agoChange license header from GPL to BSD
Wincent Colaiuta [Thu, 21 May 2009 19:09:43 +0000 (21:09 +0200)] 
Change license header from GPL to BSD

This file was overlooked in the move to the BSD license (see commit
1155628).

Signed-off-by: Wincent Colaiuta <win@wincent.com>
13 years agoSwap README.rdoc and doc/README (symlink <--> file)
Wincent Colaiuta [Wed, 13 May 2009 21:09:44 +0000 (23:09 +0200)] 
Swap README.rdoc and doc/README (symlink <--> file)

Looks like a top-level symlink won't get picked up by GitHub,
so swap things around: make the top-level item be the real
file and the item in the "doc" subdirectory can be a symlink
(RDoc will continue to generate the HTML for the README as
before).

Signed-off-by: Wincent Colaiuta <win@wincent.com>
13 years agoAdd README symlink at top level for GitHub mirror
Wincent Colaiuta [Wed, 13 May 2009 16:08:40 +0000 (18:08 +0200)] 
Add README symlink at top level for GitHub mirror

GitHub will automatically display any README found at the top
level of the tree, so set up a symlink (we'll see if it works)
from doc/README to README.rdoc.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
13 years agoFix spelling error in comment
Wincent Colaiuta [Wed, 13 May 2009 09:30:20 +0000 (11:30 +0200)] 
Fix spelling error in comment

Signed-off-by: Wincent Colaiuta <win@wincent.com>
13 years agoAdd ary_includes2, ary_includes3 functions
Wincent Colaiuta [Wed, 13 May 2009 09:04:16 +0000 (11:04 +0200)] 
Add ary_includes2, ary_includes3 functions

A fairly common pattern in the codebase is successively calling
the ary_includes function 1, 2 or 3 times. In the worst case
scenario this incurs 3 function calls and three array traversals
via a for-loop in the function.

Add 2 and 3-argument variants of the function so that we can
replace these instances with a single function call and a single
array traversal.

As shown in the benchmarking notes, this bumps the ary_includes
function from 4th place in the profile (where it was the "low-hanging
fruit") and right off the list.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
13 years agoBump version number post-release
Wincent Colaiuta [Tue, 12 May 2009 23:14:05 +0000 (01:14 +0200)] 
Bump version number post-release

Signed-off-by: Wincent Colaiuta <win@wincent.com>
13 years agoBump version number for 1.7 release 1.7
Wincent Colaiuta [Tue, 12 May 2009 22:44:49 +0000 (00:44 +0200)] 
Bump version number for 1.7 release

Normally "minor" version bumps (eg 1.6 to 1.7) are
reserved for versions which introduce new features
and "tiny" version bumps (eg 1.6 to 1.6.1) are for
maintenance (bugfix) releases.

This release doesn't contain any new features but
I am nevertheless bumping the "minor" version
number because the release does involve a fairly
major rewrite of the internals, and as such is
less conservative than a normal "maintenance"
update.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
13 years agoChange remaining instances of "_Wikitext_" to "wiki_"
Wincent Colaiuta [Tue, 12 May 2009 22:34:57 +0000 (00:34 +0200)] 
Change remaining instances of "_Wikitext_" to "wiki_"

The remaining references mostly appear in comments. The one
significant change is the renaming of the "_Wikitext_token"
method to "wiki_token".

Signed-off-by: Wincent Colaiuta <win@wincent.com>
13 years agoChange internal function prefix from "_Wikitext_" to "wiki_"
Wincent Colaiuta [Tue, 12 May 2009 22:29:20 +0000 (00:29 +0200)] 
Change internal function prefix from "_Wikitext_" to "wiki_"

Follow the pattern already established in str.c/str.h and
ary.c/ary.h, and use a short lowercase prefix with no
leading underscore for "internal" functions (that is,
functions that are for use within the C part of the extension
and are not exposed as Ruby methods).

This buys us some horizontal space and makes keeping things
in a reasonable number of columns a bit easier.

Externally exported methods still follow the old pattern of
Module_class_method (eg. Wikitext_parser_parse).

Signed-off-by: Wincent Colaiuta <win@wincent.com>
13 years agoUpdate release notes for forthcoming 1.7 release
Wincent Colaiuta [Tue, 12 May 2009 22:24:52 +0000 (00:24 +0200)] 
Update release notes for forthcoming 1.7 release

Signed-off-by: Wincent Colaiuta <win@wincent.com>
13 years agoCollapse H*_END rules into a single case
Wincent Colaiuta [Tue, 12 May 2009 22:05:25 +0000 (00:05 +0200)] 
Collapse H*_END rules into a single case

This takes nearly 90 lines off the file.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
13 years agoRemove unnecessary parens
Wincent Colaiuta [Tue, 12 May 2009 21:51:49 +0000 (23:51 +0200)] 
Remove unnecessary parens

Signed-off-by: Wincent Colaiuta <win@wincent.com>
13 years agoPass str_t output param to _Wikitext_append_entity_from_utf32_char
Wincent Colaiuta [Tue, 12 May 2009 21:46:58 +0000 (23:46 +0200)] 
Pass str_t output param to _Wikitext_append_entity_from_utf32_char

By accepting a str_t pointer instead of a char pointer the
two call sites of _Wikitext_append_entity_from_utf32_char
can be cleaned up a little.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
13 years agoRemove comment from _Wikitext_append_entity_from_utf32_char
Wincent Colaiuta [Tue, 12 May 2009 21:32:00 +0000 (23:32 +0200)] 
Remove comment from _Wikitext_append_entity_from_utf32_char

There is no point in special casing entities like "quot", "amp"
and such in this function because neither of the two call sites
would ever pass in such a code point:

- the _Wikitext_append_sanitized_link_target already explicitly
  handles all these cases, either emitting the entities manually
  or raising an exception.

- the DEFAULT case won't ever have to process those characters
  because they would have already been tokenized otherwise and
  handled in the QUOT, AMP, LESS and GREATER cases.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
13 years agoRemove Wikitext_parser_encode_special_link_target function
Wincent Colaiuta [Tue, 12 May 2009 21:23:27 +0000 (23:23 +0200)] 
Remove Wikitext_parser_encode_special_link_target function

"Special" link targets haven't been treated specially since prior
to version 1.4.0, so the Wikitext_parser_encode_special_link_target
function is literally identical to the Wikitext_parser_encode_link_target
function.

Seeing as it was only ever exposed for testing purposed and never
advertised or documented as public API, get rid of it.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
13 years agoClean up code-level docs for _Wikitext_encode_link_target function
Wincent Colaiuta [Tue, 12 May 2009 20:58:34 +0000 (22:58 +0200)] 
Clean up code-level docs for _Wikitext_encode_link_target function

Signed-off-by: Wincent Colaiuta <win@wincent.com>
13 years agoAbandon plan to eliminate ALLOC_N in _Wikitext_encode_link_target
Wincent Colaiuta [Tue, 12 May 2009 20:48:52 +0000 (22:48 +0200)] 
Abandon plan to eliminate ALLOC_N in _Wikitext_encode_link_target

It's not worth trying to eliminate this ALLOC_N because we are
writing the encoded output back to the input buffer. If we have
to use any percent escapes then we would need to do a potentially
expensive memmove operation each time we insert an escape.

(Although note, in the case where we eat leading whitespace we would
not need a memmove for that because we are effectively doing a
manual move anyway).

We could potentially add a special case which overwrote in-place
only if there were no percent escapes (ie. which only did the ALLOC_N
on seeing a percent escape, and only if there were not enough leading
whitespace to compensate for the extra characters required by the
escape) but I am not sure if it will be worth the extra complexity.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
13 years agoRemove unnecessary parens
Wincent Colaiuta [Tue, 12 May 2009 20:36:18 +0000 (22:36 +0200)] 
Remove unnecessary parens

C operator precendence makes most of these parens unnecessary
so remove them.

We don't remove the parens around the "&&" expressions even
though they aren't necessary, because without them GCC will
warn "suggest parentheses around && within ||". Better to
have a warning-free build than shave off a few bytes at any
cost.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
13 years agoMinor reshuffling in _Wikitext_encode_link_target
Wincent Colaiuta [Tue, 12 May 2009 20:35:51 +0000 (22:35 +0200)] 
Minor reshuffling in _Wikitext_encode_link_target

Preparation for future removal of ALLOC_N.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
13 years agoRename input var in _Wikitext_encode_link_target
Wincent Colaiuta [Tue, 12 May 2009 20:22:27 +0000 (22:22 +0200)] 
Rename input var in _Wikitext_encode_link_target

This is the first in a series of changes to the
_Wikitext_encode_link_target function to make it
more consistent with the other, similar
_Wikitext_append_sanitized_link_target function.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
13 years agoRemove unnecessary include
Wincent Colaiuta [Tue, 12 May 2009 10:08:17 +0000 (12:08 +0200)] 
Remove unnecessary include

We now set up the version checks before writing out the Makefile,
so this include is no longer required.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
13 years agoConditional compilation for Ruby 1.8.x and 1.9.x
Wincent Colaiuta [Tue, 12 May 2009 10:00:41 +0000 (12:00 +0200)] 
Conditional compilation for Ruby 1.8.x and 1.9.x

Detect the Ruby version in extconf.rb using the RUBY_VERSION
constant and pass this along as a C preprocessor macro (either
RUBY_1_8_x or RUBY_1_9_x).

By definition we're doing this conditional compilation because
we want to manipulate RString struct members directly, so we
tie the conditional compilation very tightly to the version
number. Older or newer versions will bail with an error.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
13 years agoPreliminary fix for Ruby 1.9 compatibility
Wincent Colaiuta [Tue, 12 May 2009 09:48:41 +0000 (11:48 +0200)] 
Preliminary fix for Ruby 1.9 compatibility

The migration to the str_t type for the output buffer broke
compatibility with Ruby 1.9.

This commit shows what things would look like if we could
do a compile-time check for 1.9 and could thus modify the code
to make it compatible.

Unfortunately this doesn't actually work because although Ruby
comes with a "version.h" file with all the necessary macros,
for some reason it isn't installed when doing "make install".

In my local testing, that means that I can build under 1.9,
but it will fall back to the system-installed (1.8) headers
and the values for RUBY_VERSION_* are not correct.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
13 years agoAdd encoding markers to benchmark files for Ruby 1.9
Wincent Colaiuta [Tue, 12 May 2009 09:47:33 +0000 (11:47 +0200)] 
Add encoding markers to benchmark files for Ruby 1.9

Without these Ruby 1.9 will choke when parsing the benchmark
files.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
13 years agoRemove unnecessary "len" variables
Wincent Colaiuta [Mon, 11 May 2009 23:13:26 +0000 (01:13 +0200)] 
Remove unnecessary "len" variables

Seeing as these expressions are short and are only evaluated once
there is no real need to store them in temporary variables; including
the expression in the relevant line is fine for readability due to
their short length.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
13 years ago_Wikitext_append_sanitized_link_target consistency changes
Wincent Colaiuta [Mon, 11 May 2009 23:08:43 +0000 (01:08 +0200)] 
_Wikitext_append_sanitized_link_target consistency changes

This makes the variable initialization order of the
_Wikitext_append_sanitized_link_target function match
that of the _Wikitext_trim_link_text function.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
13 years agoRemove unnecessary "dest" pointer in _Wikitext_append_sanitized_link_target
Wincent Colaiuta [Mon, 11 May 2009 23:07:23 +0000 (01:07 +0200)] 
Remove unnecessary "dest" pointer in _Wikitext_append_sanitized_link_target

Signed-off-by: Wincent Colaiuta <win@wincent.com>
13 years agoInvert sense of "trim" parameter in _Wikitext_append_sanitized_link_target
Wincent Colaiuta [Mon, 11 May 2009 23:03:26 +0000 (01:03 +0200)] 
Invert sense of "trim" parameter in _Wikitext_append_sanitized_link_target

Trim if "trim" is true; it makes more sense.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
13 years agoDrop INVALID_ENCODING macro
Wincent Colaiuta [Mon, 11 May 2009 22:59:09 +0000 (00:59 +0200)] 
Drop INVALID_ENCODING macro

Now that there is no conditional logic in the macro there is not
much justification for its existence. Use the literal call instead
seeing as it is so simple.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
13 years agoStyle fix
Wincent Colaiuta [Mon, 11 May 2009 22:56:32 +0000 (00:56 +0200)] 
Style fix

Signed-off-by: Wincent Colaiuta <win@wincent.com>
13 years agoAvoid allocation in _Wikitext_append_sanitized_link_target
Wincent Colaiuta [Mon, 11 May 2009 22:54:42 +0000 (00:54 +0200)] 
Avoid allocation in _Wikitext_append_sanitized_link_target

Rather than allocating a buffer and then copying (appending) to
the output buffer, append directly to the output buffer along the
way.

At the same time, drop the now unneeded dest_ptr parameter to the
_Wikitext_utf8_to_utf32 function.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
13 years agoRename _Wikitext_parser_* functions to _Wikitext_*
Wincent Colaiuta [Mon, 11 May 2009 21:30:01 +0000 (23:30 +0200)] 
Rename _Wikitext_parser_* functions to _Wikitext_*

While it makes sense to name functions that are externally
exported to the "Ruby" side following the "Module_Class_*"
pattern, it's not really justified or necessary for functions
which are for internal use only.

This is especially the case for some of these functions whose
internal purpose and use and drifted away from the external
counterparts. (For example, the _Wikitext_append_sanitized_link_target
function which no longer mirrors the externally visible
Wikitext_parser_sanitize_link_target function.)

Signed-off-by: Wincent Colaiuta <win@wincent.com>
13 years agoRename "rollback" param in _Wikitext_parser_append_sanitized_link_target
Wincent Colaiuta [Mon, 11 May 2009 21:25:29 +0000 (23:25 +0200)] 
Rename "rollback" param in _Wikitext_parser_append_sanitized_link_target

This param name doesn't make much sense; perhaps it made sense
in the distant past, but it certainly doesn't now.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
13 years agoCollapse a conditional in EXT_LINK_START case
Wincent Colaiuta [Mon, 11 May 2009 20:45:12 +0000 (22:45 +0200)] 
Collapse a conditional in EXT_LINK_START case

This is equivalent but takes less vertical space.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
13 years agoChange emit parameter of _Wikitext_dedent to bool type
Wincent Colaiuta [Mon, 11 May 2009 20:28:52 +0000 (22:28 +0200)] 
Change emit parameter of _Wikitext_dedent to bool type

For consistency with other functions which have recently switched
to bool from VALUE/Qfalse/Qtrue.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
13 years agoUpdate benchmarking notes
Wincent Colaiuta [Mon, 11 May 2009 20:12:16 +0000 (22:12 +0200)] 
Update benchmarking notes

The lion's share of the speed improvements that can be milked out
of the "str" branch has probably already been had, so update the
benchmarking notes.

Things are faster for all test cases, but the most spectacular
gains are seen in long slabs of UTF-8 text, where things run over
twice as fast.

From here on more speed can really probably only be eeked out of
micro-optimizations.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
13 years agoMake link_text parameter a pointer to str in append hyperlink function
Wincent Colaiuta [Mon, 11 May 2009 20:08:52 +0000 (22:08 +0200)] 
Make link_text parameter a pointer to str in append hyperlink function

This change allows us to get rid of unnecessary Ruby String instance
instantiations in a couple of different places.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
13 years agoRemove unnecessary string_from_str call in _Wikitext_parser_encode_link_target
Wincent Colaiuta [Mon, 11 May 2009 20:04:07 +0000 (22:04 +0200)] 
Remove unnecessary string_from_str call in _Wikitext_parser_encode_link_target

Signed-off-by: Wincent Colaiuta <win@wincent.com>
13 years agoMake link_target parameter a pointer to str in append hyperlink function
Wincent Colaiuta [Mon, 11 May 2009 19:59:36 +0000 (21:59 +0200)] 
Make link_target parameter a pointer to str in append hyperlink function

This change allows us to get rid of unnecessary Ruby String instance
instantiations in about 8 different places.

Signed-off-by: Wincent Colaiuta <win@wincent.com>