dry

How to remove duplication in Makefile?

不想你离开。 提交于 2019-12-01 08:47:40
Is there a way to simplify this sort of repetition in a Makefile? duo = ./node_modules/.bin/duo build: lib/background/build lib/page/build lib/popup/build lib/background/build: lib/background/build/build.js lib/background/build/build.css lib/page/build: lib/page/build/build.js lib/page/build/build.css lib/popup/build: lib/popup/build/build.js lib/popup/build/build.css lib/background/build/build.js: lib/background/index.js node_modules component.json @mkdir -p lib/background/build @$(duo) lib/background/index.js > lib/background/build/build.js lib/page/build/build.js: lib/page/index.js node

AngularJS: Is there a better way to achieve this than the one specified?

落花浮王杯 提交于 2019-12-01 06:38:44
I use a template that generates a Bootstrap tab layout. Like below: <div class="a"> <ul class="nav nav-bar nav-stacked" role="tabs"> <li><a href="#home"></a></li> ... </ul> <div class="tab-content"> <div id="home">abc</div> ... </div> </div> Now this is pretty simple and straightforward tab navigation that can be hardcoded and achieved. I have a dynamic ng-repeat on the ul's li and the tab-content's div s. The JSON that I get from the REST service is something that contains the data for the tabs and the content to be displayed inside the tab-content within a single object. For eg: { "0": "a":

How to remove duplication in Makefile?

谁都会走 提交于 2019-12-01 05:47:37
问题 Is there a way to simplify this sort of repetition in a Makefile? duo = ./node_modules/.bin/duo build: lib/background/build lib/page/build lib/popup/build lib/background/build: lib/background/build/build.js lib/background/build/build.css lib/page/build: lib/page/build/build.js lib/page/build/build.css lib/popup/build: lib/popup/build/build.js lib/popup/build/build.css lib/background/build/build.js: lib/background/index.js node_modules component.json @mkdir -p lib/background/build @$(duo) lib

How do I implement a common interface for Django related object sets?

笑着哭i 提交于 2019-12-01 05:23:59
问题 Here's the deal: I got two db models, let's say ShoppingCart and Order . Following the DRY principle I'd like to extract some common props/methods into a shared interface ItemContainer . Everything went fine till I came across the _flush() method which mainly performs a delete on a related object set. class Order(models.Model, interface.ItemContainer): # ... def _flush(self): # ... self.orderitem_set.all().delete() So the question is: how do I dynamically know wheter it is orderitem_set or

AngularJS: Is there a better way to achieve this than the one specified?

微笑、不失礼 提交于 2019-12-01 03:10:26
问题 I use a template that generates a Bootstrap tab layout. Like below: <div class="a"> <ul class="nav nav-bar nav-stacked" role="tabs"> <li><a href="#home"></a></li> ... </ul> <div class="tab-content"> <div id="home">abc</div> ... </div> </div> Now this is pretty simple and straightforward tab navigation that can be hardcoded and achieved. I have a dynamic ng-repeat on the ul's li and the tab-content's div s. The JSON that I get from the REST service is something that contains the data for the

rails - DRY respond_to with repeated actions

China☆狼群 提交于 2019-12-01 02:40:45
In one of my rails controller, I must respond to several types of formats, so I use the typical respond_to chain: respond_to do |format| format.html { ... } format.mobile { ... } format.jpg { ... } format.xml { ... } format.js { ... } end Usually that the { ... } part is repeated on several formats. What is the best way to stay DRY on this case? On an scenario in which html , mobile and xml have a "repeated" action, I'd like to do something like this: respond_to do |format| format[:html, :mobile, :xml] { ... } format.jpg { ... } format.js { ... } end Thanks a lot. Eric Hu Have you tried format

Rails: Calling one Model from another Model. Why is this not possible?

旧街凉风 提交于 2019-12-01 00:51:32
I have the following Model... class Room < ActiveRecord::Base belongs_to :hotel belongs_to :layout has_many :visits validates :number, presence: true validates :rate, presence: true validates :smoking, presence: true def self.rooms_with_smoking(smoking) self.where('smoking = ?', smoking) end def self.occupied_rooms(from_date, to_date) #24-26 self.joins(:visits).where('date >= ? and date <= ?', from_date, to_date).uniq end def self.vacant_rooms(from_date, to_date) self.where.not(id: Room.occupied_rooms(from_date, to_date)) end def self.blahblah(occupancy_count, smoking, from_date, to_date)

DRYing rails view: partial vs helper [duplicate]

左心房为你撑大大i 提交于 2019-11-30 14:39:12
问题 This question already has answers here : When to use Helpers instead of Partials (6 answers) Closed 5 years ago . I need an advice on best practices for DRYing view code. I have three classes (NewsItem, RssItem and BlogItem) in my app, that use separate views, but have similar parts in them. One of the parts is such: <% if current_user %> <footer> <%= marks_bar(@item) %> <%= favorite_button(@item, "blog_item") || delete_from_favorite_button(@item, "blog_item") %> <%= share_button(@item) %> <%

Localized project with several targets with localized app names

余生长醉 提交于 2019-11-30 14:31:10
问题 I have recently merged together 5 of my stand-alone projects into one project to have a common code base. So now I have one project with 5 targets instead. Each target has the same fileset, except for some files which differ for each target (such as Default.png, and icons files amongst others). My application is translated to 7 languages with English as default. The other languages are: Swedish, Dutch, German, French, Polish and Spanish. Now I would also like to translate the name of the

Should mapping value be declared in a constant or as an enum?

时间秒杀一切 提交于 2019-11-30 13:43:50
I see this scattered throughout code base: @RequestMapping(value = "myValue") I would prefer to use something like this: @RequestMapping(value = Constants.myValue) It seems to break DRY using the actual String value within @RequestMapping instead of constant. But is this good code practice? Should I use an enum instead? I may need to use Constants.myValue elsewhere in the code base. Should I use an enum instead? You can't. Annotation variables must be compile-time constants. Enums and String literals both are, but you can't create an enum that is a String and @RequestMapping needs a String