-
-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support nested folder hierarchies for projections #14
Comments
I also recently realized two Clojure conventions, Your proposed solution has an underscore that sprang out of nowhere. |
There would need to be some (maybe user defined) way to separate the path components, I would think. Maybe I'm wrong about that though. What about named regex groups for the file glob? Something like: {
"application/modules/(*)/controllers/(*)Controller.php": {
"command": "controller",
"name": "{1}_{2}"
}
} The named groups, and the "name" option could be optional so as to not break existing .projections.json configuration. |
Maybe if you drop the parentheses, but that's still a whole lot of added complexity for a relatively dumb problem. I'd sooner just force a join with |
Simplicity is fine. I like the sound of putting a |
Seconding the motion to force a join with / On 11 April 2014 12:11, Griffin Smith notifications@github.com wrote:
|
Note that smooshing just means you'd have to write |
Can someone confirm that both of these return the expected results? :echo glob("application/modules/**/*controllers/**/*Controller.php")
:echo glob("application/modules/**/*/controllers/**/*Controller.php") |
Looks right to me |
@glittershark I don't know what you mean. |
If you're referring to my other comment, I deleted it because I didn't know what I meant either :) |
Was leaning towards smooshing then realized false positives for |
Seems sound to me. Looking forward to support for this! |
I feel like With this style, each wildcard is kind of like a command argument, each with dedicated completion. It would be nice if completion would allow wildcard positions to be skipped (auto-filled), but I can see that getting complicated. How would multiple wildcards affect the language used for alternates and templates? Would |
Uh, could it? Last I checked, you can't have directory separators in file names on any sane system. |
What about the |
The |
I might not be thinking very hard, but I can't come up with an ambiguous case. |
Let's say you have
as your pattern. Then you have these files:
Using |
There it is. Yeah, that's no good. =\ |
It gets ambiguous the second you match I'd actually like to switch from |
Correct me if I'm wrong, but for a case like that,
versus the following with
Both are cleared up in this case. But |
I feel like there's a case to be made for splitting apart the behavior of |
You're right. I guess the first Spaces are arguable in the title case but absolutely ridiculous in the context of my Clojure examples. |
@glittershark I'm trying to move away from the globbing syntax not double down on it. |
Though if I can't switch to |
What about creating files? How would you infer where to unsmoosh? |
I guess greedy/lazy actually means "all of the nesting"/"no nesting". |
Sounds kind of limiting. I'm picking up that we might be thinking of this differently. I'm thinking that each submatch would be accessible independently when it comes to alternates and templates. I don't know what the notation would look like, but a possible example is this:
|
I want some pattern for |
I'm also thinking forward to potential abstractions like |
Does anyone even know how well projectile works on Windows? Looking at the code and first order of business will be making sure we're doing the right thing with slashes. |
I think Windows doesn't care whether you use forward or backward slashes. That said, I haven't tried it. |
Yes you can pass either slash to glob but globbing is just one piece of the puzzle. We need to take it into account in equality checks for example. I've think I've been diligent about that but without any testing it's hard to say. |
After sleeping on it, I felt that given that We will probably also need to add an expansion like |
Well this issue got quiet. I iterated a few times, and I'm pretty satisfied with the result. |
This is pretty sweet. Thanks! |
Just wanting to provide a use case which I don't believe is covered by the current solution. This same convention used by Kohana is used by some AngularJS projects. Off the top of my head, some other frameworks that provide this structure as convention include Django and Symfony. Many Marionette.JS projects also take this approach. I'm pretty sure that Rails projects are similar, but it's scaffolding makes this less of an issue. An example of the project that I'm working on is quite similar to Kohana with the following structure: src:
- common:
- module.coffee
- partials:
- index.jade
- other.jade
- controllers:
- index.coffee
- other.coffee
- directives:
- other.coffee
- specific:
- module.coffee
- partials:
- index.jade
- some.jade
- controllers:
- index.coffee
- some.coffee
- directives:
- some.coffee It would be nice to have a more powerful way of doing this, because I would like to be able to create a new files using the template functionality from projectile. For instance, a command like This file would ideally use the already-existing expansions from projectile to mock out the following initial template: angular.module 'common'
.service 'common.controllers.index', [
'$scope'
].concat ($scope) ->
angular.extend $scope, {} The module is the name of the first glob. The service name is essentially the path from the first to last glob replacing slashes with dots. It's a fairly common thing for Angular modules to map to the filesystem in this way. Right now, I am needing to create specific keys for every module - but it's a bit of a task because there are quite a few of them. The results are similar to this: {
"src/common/directives/*.coffee": {"command": "CommonDirective"},
"src/common/services/*.coffee": {"command": "CommonService"},
"src/common/controllers/*.coffee": {"command": "CommonService"},
"src/*/module.coffee": {"command": "Module"}
} Most of this functionality exists already in the project, but being able to glob and get references to each one is the missing component for these types of file structures is the single missing piece |
Links to real world projects would be helpful. Those CamelCase commands are irking me. Makes me wonder if I should be enforcing some sort of normalization. |
The majority of Django apps follow this pattern, where there's a set of core files in either the project root or in a specific Some examples: Related articles: The camel case commands seemed a bit odd to me, also. I felt like it was more conventional to type |
Having thought about it a few days, I think the next logical step on the path I've set us down is to allow multiple Not finding either of those repos or blog posts to contain a concrete example of nesting that can't be handled by The official projectionist convention for commands is lowercase, squished together. This is already partially enforced by stripping out punctuation, and a future version might add a |
This might just be a misunderstanding in how projectionist works with the ** glob, but I don't see how to reference it as a pattern (in a template or alternate, for example) or how to use it for creating new files. Are these not supported use cases? |
The |
Seems like that solved most of the issues, actually. Thank you for clarifying. Seems like this is one is a working example for anyone that might be confused on a similar project: {
"src/**/services/*.coffee": {
"command": "service",
"template": [
"angular.module '{dirname|dot}'",
" .service '{dirname|dot}.controllers.{basename|underscore}', [",
" '$rootScope'",
"",
" ].concat ($rootScope) ->"
]
}
} |
One lingering issue is that concatenating them together means that I have no context of There is a common use case in Django apps where |
I don't understand the question. |
For instance, a user may have a file named :Eservice common/twitter/tweet The slashes seem really awkward in this situation. It might be nice to allow spaces where globs are separated, but this is quite a digression. This interface is ambiguous, because a user running the previous command would be attempting to define a module called common.services.twitter.tweet. However, getting this information for the template is impossible because One common example of where this use case would occur is when there is a Django project with a package that defines I was specifically asking whether using templates in this way was an intended/supported use case, or if it's something that shouldn't be supported? If this is an intentionally unsupported use case then the current implementation seems to work. If it should be supported then it might make more sense to allow a more powerful use case. |
Bigger problem there is that the generated filename would be Once that's fixed, adding another template expansion or two is a comparatively straightforward process. |
Good point. That definitely seems like the right solution as long as it's possible to reference the separate globs independently in the template! The other concern that is potentially of interest here is whether having two globs implies an additional argument through the command. Would a user use |
Not if I can help it. On Tue, Apr 29, 2014 at 11:37 PM, Brandon R. Stoner <
|
I think two new transformations are in order: one that returns the first component, and one that returns all but the first. These will be necessary for cases where My use case will involve a lot of Actually, with the two transformations I'm proposing (the biggest obstacle for which is what to call them), the |
I'd probably just repurpose |
Just to note, I've seen projects where not having multiple src\/([\w\/\\]+)\/(directives|controllers)\/([\w\/\\]+)\.coffee
A live view of the expression matches can be seen here. Hovering over each line of text will show a tooltip of expected matches in these cases. It seems like adding limitations such as allowing only one |
Handle multi-level globs by separating the passed file with `/`. See tpope/vim-projectionist#14
Some tools like Zend Framework have a folder hierarchy something like the following:
It'd be nice in projectile if I could define a projection like:
so I could
EController mod1_my
The text was updated successfully, but these errors were encountered: