Git Product home page Git Product logo

underscorecf's Introduction

Underscore.cfc

This project is an UnderscoreJS port for Coldfusion.

Read the official documentation here: russplaysguitar.github.com/UnderscoreCF/

Build Status

Underscore.cfc is a utility-belt library that provides a lot of the functional programming support that you would expect in Prototype.js (or Ruby). It provides dozens of functions that support both the usual functional suspects: map, select, invoke - as well as more specialized helpers: function binding, sorting, deep equality testing, and so on. It delegates to built-in functions where applicable.

Underscore.cfc is compatible with Adobe Coldfusion 10 and Railo 4.

Contributing

Contributions are welcome.

To contribute:

  • Fork the project.
  • Make a feature branch: git checkout -b feature_branch
  • Make your changes.
  • Add tests.
  • Send a pull request.

Copyright

Copyright © 2012 Russ Spivey. See LICENSE.txt for details.

underscorecf's People

Contributors

alkamin avatar detarmstrong avatar dikklop avatar elpete avatar honeyd avatar jfrux avatar russplaysguitar 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

Watchers

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

underscorecf's Issues

toArray() uses for-in loop on a list variable which is not supported

I tried using the code in toArray() function for a query and found out it is using cfscript for-in loop on a list !!! This produces an error.

"for (var colName in arguments.obj.columnList) {..."

from CF ref:
"Note: Unlike the cfloop tag, CFScript for-in loops do not provide built-in support for looping over queries and lists."

http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec0a0e0-7fdf.html#WSc3ff6d0ea77859461172e0811cbec0a0e0-7fe8

variables._ is undefined

When trying to use any underscore function that depends another underscore function I get an error

'_ is not defined'

it seems that it is trying to access the _ in the variables scope set on line 14

variables._ = this;

This is on cf10 windows 7. I'm not the most familiar with Coldfusion, and scopes still seem a mystery to me.

Make toQuery(arrayOfStructs) handle variable-size structs

It would be nice if this worked:

_.toQuery([{a: 'a'}, {b: 'b'}]);

I would expect it to return a query with the following data:

| a | b |
---------
| a |   |
|   | b |

It would be nice if the empty slots were some kind of null, but an empty string may also be acceptable?

_.type(variable)

There are so many places in Underscore that have to check multiple types in order to determine what type a variable really is. For instance, some variables pass both isStruct() and isObject(), or isArray() and isXmlDoc(). This is compounded by the fact that Railo 4 and CF10 don't respond the same.

It would be great to replace all of those weird logical statements with clearer statements using _.type().

_.type() should return a string. Possible values:

  • simpleValue (boolean, string or numeric)
  • array
  • struct
  • object
  • query
  • xml
  • function (closure, custom function, or anonymous function)

_.type() should return the same values in both cfml engines.

CI with Jenkins

This is mostly a reminder to myself to get Underscore setup on my Jenkins server. Just one pre-requisite. Gotta get my box updated to CF10 first. :)

Failing tests on all versions of CF10 (all available updates)

I initially had trouble as of CF10 update 5, but have since rolled back to every previous update level and confirmed that the issue remains for all of them. I'm starting to think it may be a bug in CF, and if further testing proves that to be true I'll be contacting the CF engineering team.

The issue I'm seeing is that several tests are failing with similar results to:

Expected: [1, 2, 3], Received: [1, 2.0, 3.0]

The following tests are all exhibiting this behavior for me (OSX 10.7.5, Apache 2.2):

  • examplesTest
    • testRange
    • testTimes
  • collectionsTest
    • testMap
  • arraysTest
    • testRange
  • objectsTest
    • testKeys

I even tried adding a fix() where appropriate, but it had no effect whatsoever.

Issues with Railo (not Underscore's fault)

Okay, I just posted an issue with the Railo Group about the "this" scope and whether or not I'm approprately using it lmao...

Here is my post, let me know if you think I'm just a n00b or if it should behave this way.


I have some concerns with components that implement other components potentially losing site of the "this" scope.
Maybe it's just something with my code but the best way I can explain it is with pseudo-code for now. That's all I have time for.
It could be 'just me' but I figured I would share in case I'm doing something wrong.

Let's say we have 1 cfc, we'll call it "utilities.cfc" which has the following code:

component {
public any function init() {
return this;
};
public any function mapper(arr,func) {
      func(do,something,now);
};

public any function doer(arr,func) {
     func(do,something,now);
};

public any function donter(arr,func) {
       func(do,something,now);
};
}

THEN, we have another CFC that uses this utilities.cfc, we'll call it 'worker.cfc' which has code like such...

component {
     public any function init() {
           variables.util = new utilities();
     }


     public any function fooer(arr) {
            util.mapper(arr,this.doerFunc);
     }

     public any function doerFunc(this,that,andthis) {
           writeDump(var=this,abort=true); //'this' now represents the "utilities.cfc" because I passed this function to the util.mapper.
     }
}

Is this normal behavior? am I just stupid? :D
I mean, I assume the reason it's acting this way is because 'doerFunc' is passed as a function expression to the utilities.cfc function which now executes it under it's own scope but is this intentional? Should this work this way?

I'll try to get a real test case up as soon as I can.

Please advise.

Sincerely,
Joshua F. Rountree

Publish to ForgeBox.io?

I noticed this had a box.json but isn't published to forgebox.io.
Would someone be able to do this?
Or would you mind if I do it?

Add toXml(collection, [*elementNames])

There are a lot of different ways to convert json to xml, but the goal here is to produce the simplest xml possible given the particular collection.

XML element names would default to the type of collection. The elementNames arguments offer a way to name the elements at levels without keys (arrays). See the examples below for details.

There is no json representation for xml attributes.

If more customized xml is needed, then an iterative method (like _.each()) should be used instead.

Examples

Arrays:

_.toXml([1, 2, 3]) =>
<array>
  <element>1</element>
  <element>2</element>
  <element>3</element>
</array>

_.toXml([1, 2, 3], 'numbers') =>
<numbers>
  <element>1</element>
  <element>2</element>
  <element>3</element>
</numbers>

_.toXml([1, 2, 3], 'numbers', 'number') =>
<numbers>
  <number>1</number>
  <number>2</number>
  <number>3</number>
</numbers>

Structs:

_.toXml({one: 1, two: 2, three: 3}) =>
<struct>
  <one>1</one>
  <two>2</two>
  <three>3</three>
</struct>

_.toXml({one: 1, two: 2, three: 3}, 'numbers') =>
<numbers>
  <one>1</one>
  <two>2</two>
  <three>3</three>
</numbers>

Arrays of Structs:

_.toXml([{one: 1, two: 2, three: 3}, {four: 4, five: 5, six: 6}]) =>
<array>
  <struct>
    <one>1</one>
    <two>2</two>
    <three>3</three>
  </struct>
  <struct>
    <four>4</four>
    <five>5</five>
    <six>6</six>
  </struct>
</array>

_.toXml([{one: 1, two: 2, three: 3}, {four: 4, five: 5, six: 6}], 'items', 'numbers') =>
<items>
  <numbers>
    <one>1</one>
    <two>2</two>
    <three>3</three>
  </numbers>
  <numbers>
    <four>4</four>
    <five>5</five>
    <six>6</six>
  </numbers>
</items>

Calling slice with a "to" 1 value greater than the length of the array causes an error

Here is how to reproduce the error...

<cfset _ = new modules.underscorecf.Underscore() />

<cfscript>
writeDump(var = "hello");
myArray = [1,2,3,4];

bleh = _.slice(myArray, 1, 5);

</cfscript>

The problem is in line 874 (the 2nd line below). It should be (to >= (len + 1)) ? len + 1 (notice the >= instead of just >).

to = (!structKeyExists(arguments, 'to')) ? len + 1 :
(to > (len + 1)) ? len + 1 :
(to < 0) ? to + len + 1 :
to + 1;

It basically tries to assign the to value greater than the length of the array. If you use a value that is more than just 1 value greater (to=10 when the length of the array is 4), it all works great. It is only when the to is exactly 1 value greater than the length of the array.

I don't mind trying to help by putting in a pull request (assuming you're seeing the same thing I am). Are you still accepting pull requests? Seems like from reading through the repo that maybe tests are already failing or something?

Let me know what you think. Thanks!

Fix unit tests: expected vs. actual ordering

I think that most of the assertions have the expected/actual values swapped. It was originally done this way because the Underscore.js tests were in this order (which is not a good reason).

This should be fixed, but it is mind numbing work...

For example:

assertEquals(_.flatten(result), [1,2,1,2], 'initial works with _.map');

should be:

assertEquals([1,2,1,2], _.flatten(result), 'initial works with _.map');

See http://wiki.mxunit.org/display/default/Built-In+Assertions

_.toQuery(arrayOfStructs)

Currently Underscore.cfc supports processing queries, but the result is always an array of structs. It would be nice to be able to convert that back into a query.

_.extend() not copying empty properties

I'm trying to mixin a cfc's functions and "property" definitions, what is the best way to do this without initing?

For instance,

this = _.extend(this,new Paths());

I'd love to just be able to mixin the methods / property definitions of "Paths" instead of initing it and returning itself... There's gotta be a better way!

Add _.REReplace(string, regex, callback, [scope], [context])

Currently, you cannot pass a callback to REReplace(). I propose adding _.REReplace(string, regex, callback, [scope], [context]) to the library. If a substring is passed instead of a callback, then it would defer to the original REReplace(). Otherwise, it would work similarly to the JS replace() function, which passes the regex match and any group captures to the callback function. To maintain logical similarity to the original REReplace(), the optional scope parameter would work the same as it does in the original.

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.